此代码用于计算某些给定坐标的总距离,但我不知道为什么它不起作用.
错误是: Error in lis[[i]] : attempt to select less than one element.
这是代码:
distant<-function(a,b)
{
return(sqrt((a[1]-b[1])^2+(a[2]-b[2])^2))
}
totdistance<-function(lis)
{
totdis=0
for(i in 1:length(lis)-1)
{
totdis=totdis+distant(lis[[i]],lis[[i+1]])
}
totdis=totdis+distant(lis[[1]],lis[[length(lis)]])
return(totdis)
}
liss1<-list()
liss1[[1]]<-c(12,12)
liss1[[2]]<-c(18,23)
liss1[[4]]<-c(29,25)
liss1[[5]]<-c(31,52)
liss1[[3]]<-c(24,21)
liss1[[6]]<-c(36,43)
liss1[[7]]<-c(37,14)
liss1[[8]]<-c(42,8)
liss1[[9]]<-c(51,47)
liss1[[10]]<-c(62,53)
liss1[[11]]<-c(63,19)
liss1[[12]]<-c(69,39)
liss1[[13]]<-c(81,7)
liss1[[14]]<-c(82,18)
liss1[[15]]<-c(83,40)
liss1[[16]]<-c(88,30)
Run Code Online (Sandbox Code Playgroud)
输出:
> totdistance(liss1)
Error in lis[[i]] : attempt to select less than one element
> distant(liss1[[2]],liss1[[3]])
[1] 6.324555
Run Code Online (Sandbox Code Playgroud) 我所做的是按照官方 github 站点上的说明进行操作
!git clone https://github.com/NVIDIA/apex
!cd apex
!pip install -v --no-cache-dir ./
Run Code Online (Sandbox Code Playgroud)
它给了我错误:
ERROR: Directory './' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.
Exception information:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 178, in main
status = self.run(options, args)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/install.py", line 326, in run
self.name, wheel_cache
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 268, in populate_requirement_set
wheel_cache=wheel_cache
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/req/constructors.py", line 248, in install_req_from_line
"nor 'pyproject.toml' found." % name
pip._internal.exceptions.InstallationError: Directory './' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.
Run Code Online (Sandbox Code Playgroud) 这是我定义的模型,它是具有2个完全连接层的简单lstm。
import copy
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
class mylstm(nn.Module):
def __init__(self,input_dim, output_dim, hidden_dim,linear_dim):
super(mylstm, self).__init__()
self.hidden_dim=hidden_dim
self.lstm=nn.LSTMCell(input_dim,self.hidden_dim)
self.linear1=nn.Linear(hidden_dim,linear_dim)
self.linear2=nn.Linear(linear_dim,output_dim)
def forward(self, input):
out,_=self.lstm(input)
out=nn.Dropout(p=0.3)(out)
out=self.linear1(out)
out=nn.Dropout(p=0.3)(out)
out=self.linear2(out)
return out
Run Code Online (Sandbox Code Playgroud)
x_train和x_val是带有shape的float数据帧(4478,30),而y_train和y_val是带有shape的float df(4478,10)
x_train.head()
Out[271]:
0 1 2 3 ... 26 27 28 29
0 1.6110 1.6100 1.6293 1.6370 ... 1.6870 1.6925 1.6950 1.6905
1 1.6100 1.6293 1.6370 1.6530 ... 1.6925 1.6950 …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的项目列表:
lgenre[8:15]
[['Action'],
['Action', 'Adventure', 'Thriller'],
['Comedy', 'Drama', 'Romance'],
['Comedy', 'Horror'],
['Animation', "Children's"],
['Drama'],
['Action', 'Adventure', 'Romance']]
Run Code Online (Sandbox Code Playgroud)
我想要的是:
id Action Adventure Thriller Comedy Drama Romance Horror Animation Children's
0 0 1 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
2 2 0 0 0 1 1 1 0 0 0
3 3 0 0 0 1 0 0 1 0 0
4 4 0 0 0 0 0 0 …Run Code Online (Sandbox Code Playgroud) fastLm()比...慢得多lm().基本上,我只是打电话lm()和fastLm()使用相同的公式和数据,但fastLm()似乎要慢得多lm().这可能吗?我只是不知道这怎么可能发生?
dim(dat)
#[1] 87462 90
##
library(Rcpp)
library(RcppEigen)
library(rbenchmark)
benchmark(fastLm(formula(mez),data=dat),lm(formula(mez),data=dat))
test replications elapsed relative user.self sys.self user.child sys.child
1 fastLm(formula(mez), data = dat) 100 195.81 7.079 189.36 6.27 NA NA
2 lm(formula(mez), data = dat) 100 27.66 1.000 24.52 3.02 NA NA
summary(mez)
Call: lm(formula = totalActualVal ~ township + I(TotalFinishedSF^2) +
mainfloorSF + nbrFullBaths + township + range + qualityCodeDscr +
TotalFinishedSF:range + nbrBedRoom + PCT_HISP, data = …Run Code Online (Sandbox Code Playgroud)