- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试使用C++ PyTorch API使用randperm
生成置换整数索引的列表时,所得张量具有CPUFloatType{10}
的元素类型而不是整数类型:
int N_SAMPLES = 10;
torch::Tensor shuffled_indices = torch::randperm(N_SAMPLES);
cout << shuffled_indices << endl;
退货
9
3
8
6
2
5
4
7
1
0
[ CPUFloatType{10} ]
不能用于张量索引,因为元素类型是float而不是整数类型。当tryig使用
my_tensor.index(shuffled_indices)
我得到
terminate called after throwing an instance of 'c10::IndexError'
what(): tensors used as indices must be long, byte or bool tensors
环境:
最佳答案
这是因为用torch创建的任何张量的默认类型始终是float
。否则,必须使用TensorOptions
参数struct指定它:
int N_SAMPLES = 10;
torch::Tensor shuffled_indices = torch::randperm(N_SAMPLES, torch::TensorOptions().dtype(at::kLong));
cout << shuffled_indices.dtype() << endl;
>>> long
关于c++ - PyTorch C++ API中的 `randperm`不应该返回默认类型为int的张量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63500671/
在 Matlab 中 p = randperm(n,k) returns a row vector containing k unique integers selected randomly fro
我知道在 Matlab 中,有一个名为 randperm 的函数,它基本上返回数字的随机排列。 例如,randperm(6) 返回 [3 2 6 4 1 5]。 在iOS中有类似的东西吗? 最佳答案
当我尝试使用C++ PyTorch API使用randperm生成置换整数索引的列表时,所得张量具有CPUFloatType{10}的元素类型而不是整数类型: int N_SAMPLES = 10;
I have searched on stackoverflow for people facing similar issues and this topic Replicating MATL
I have searched on stackoverflow for people facing similar issues and this topic Replicating MATL
我们在MatLab中有一个魔术函数,它可以生成一个魔方。然而,它总是给出相同的正方形,而对于给定的维度可以有多个可能的幻方。。现在,我想随机生成一个给定维数的幻方,这里有一段代码:。它几乎运行得很好。
我是一名优秀的程序员,十分优秀!