假定具有以下形状的火炬张量:
x = torch.rand(20, 1, 120, 120)
Run Code Online (Sandbox Code Playgroud)
我现在想要的是获取每个120x120矩阵的最大值的索引。为了简化问题,我将首先x.squeeze()
使用shape [20, 120, 120]
。然后,我想获取火炬张量,它是具有shape的索引列表[20, 2]
。
我该如何快速完成?
我试图绘制地形与GL_TRIANGLE_STRIP
和glDrawElements
,但我有一个很艰难的时间去了解背后的东西指数glDrawElements
...
这是我到目前为止所拥有的:
void Terrain::GenerateVertexBufferObjects(float ox, float oy, float oz) {
float startWidth, startLength, *vArray;
int vCount, vIndex = -1;
// width = length = 256
startWidth = (width / 2.0f) - width;
startLength = (length / 2.0f) - length;
vCount = 3 * width * length;
vArray = new float[vCount];
for(int z = 0; z < length; z++) {
// vIndex == vIndex + width * 3 || width * 3 = 256 * …
Run Code Online (Sandbox Code Playgroud) 我想知道是否有人可以帮助我理解指数如何与glDrawElements一起使用.在下面的例子中(取自http://www.everita.com/lightwave-collada-and-opengles-on-the-iphone),作者提到你只能有一套索引,在这种情况下
const GLushort tigerBottomIndices[] = {
0,1,2,
3,0,4,
1,5,6,
…
Run Code Online (Sandbox Code Playgroud)
};
我的问题是这些指数描述了什么?我是否正确地认为前三个是顶点位置,后三个是相应的法线,后三个是纹理合并?
提前致谢 !
#import "OpenGLCommon.h"
const Vertex3D tigerBottomPositions[] = {
{0.176567, 0.143711, 0.264963},
{0.176567, 0.137939, 0.177312},
{0.198811, 0.135518, 0.179324},
…
};
const Vertex3D tigerBottomNormals[] = {
{-0.425880, -0.327633, 0.350967},
{-0.480159, -0.592888, 0.042138},
{-0.113803, -0.991356, 0.065283},
…
};
const GLfloat tigerBottomTextureCoords[] = {
0.867291, 0.359728,
0.779855, 0.359494,
0.781798, 0.337223,
…
};
const GLushort tigerBottomIndices[] = {
0,1,2,
3,0,4,
1,5,6,
…
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, tigerTextures[5]);
glVertexPointer(3, GL_FLOAT, …
Run Code Online (Sandbox Code Playgroud) 我想在Python中找到一种快速的方法(没有for循环)来分配数组的重新索引索引.这是使用for循环的期望结果:
import numpy as np
a=np.arange(9, dtype=np.float64).reshape((3,3))
# The array indices: [2,3,4] are identical.
Px = np.uint64(np.array([0,1,1,1,2]))
Py = np.uint64(np.array([0,0,0,0,0]))
# The array to be added at the array indices (may also contain random numbers).
x = np.array([.1,.1,.1,.1,.1])
for m in np.arange(len(x)):
a[Px[m]][Py[m]] += x
print a
%[[ 0.1 1. 2.]
%[ 3.3 4. 5.]
%[ 6.1 7. 8.]]
Run Code Online (Sandbox Code Playgroud)
当我尝试添加x
到a
索引时,Px,Py
我显然得不到相同的结果(3.3对3.1):
a[Px,Py] += x
print a
%[[ 0.1 1. 2.]
%[ 3.1 4. 5.]
%[ …
Run Code Online (Sandbox Code Playgroud) 从两个列表开始,例如:
lstOne = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
lstTwo = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
Run Code Online (Sandbox Code Playgroud)
我想让用户输入他们想要提取的项目数,占总列表长度的百分比,以及每个列表中随机提取的相同索引.例如,说我想要50%的输出
newLstOne = ['8', '1', '3', '7', '5']
newLstTwo = ['8', '1', '3', '7', '5']
Run Code Online (Sandbox Code Playgroud)
我使用以下代码实现了这一点:
from random import randrange
lstOne = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
lstTwo = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
LengthOfList = len(lstOne)
print LengthOfList
PercentageToUse = …
Run Code Online (Sandbox Code Playgroud) 我下面的代码给出了以下错误"IndexError:数组索引太多".我对机器学习很新,所以我对如何解决这个问题一无所知.任何形式的帮助将不胜感激.
train = pandas.read_csv("D:/...input/train.csv")
xTrain = train.iloc[:,0:54]
yTrain = train.iloc[:,54:]
from sklearn.cross_validation import cross_val_score
clf = LogisticRegression(multi_class='multinomial')
scores = cross_val_score(clf, xTrain, yTrain, cv=10, scoring='accuracy')
print('****Results****')
print(scores.mean())
Run Code Online (Sandbox Code Playgroud) 我想从名为 dt 的数据表中提取第 4、5、6 列
以下方法有效:
dt[, c(4,5,6)]
Run Code Online (Sandbox Code Playgroud)
但以下没有:
a = c(4,5,6)
dt[, a]
Run Code Online (Sandbox Code Playgroud)
事实上,第二种方法给了我一个结果:
4 5 6
Run Code Online (Sandbox Code Playgroud)
有人能告诉我为什么会这样吗?这两种方法看起来和我一样。
在遗留代码中我发现了一个索引如下:
CREATE CLUSTERED INDEX ix_MyTable_foo ON MyTable
(
id ASC,
name ASC
)
Run Code Online (Sandbox Code Playgroud)
id
如果我理解正确,该索引对于单独查询列或id
和很有用name
。我说的对吗?
因此,它可能会通过执行以下操作来改进记录检索:
select someColumn from MyTable where id = 4
Run Code Online (Sandbox Code Playgroud)
但它对这个查询没有任何作用:
select someColumn from MyTable where name = 'test'
Run Code Online (Sandbox Code Playgroud) 我是一名 Windows C# 开发人员,刚接触 iOS/SwiftUI 开发,我想我已经陷入了困境。
我有一个带有 @Binding 变量的视图:
struct DetailView: View {
@Binding var project: Project
Run Code Online (Sandbox Code Playgroud)
该项目是一个包含任务数组的对象。我循环遍历项目的任务以显示其名称和一个开关,其状态由任务的变量 isComplete 确定。
ForEach(filteredTasks.indices, id: \.self) { idx in
HStack {
Text(filteredTasks[idx].phase)
.font(.caption)
Spacer()
Text(filteredTasks[idx].name)
Spacer()
Toggle("", isOn: self.$filteredTasks[idx].isComplete)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我花了相当长的时间才完成这段代码,我发现我必须遵循带有“索引”选项的示例才能使切换单独处理每个任务,并确保其 isComplete 值被救了。
接下来,我想根据任务变量、阶段(其值为 Planning、Construction 或 Final)过滤任务列表。因此,我创建了 4 个按钮(每个阶段一个,然后是“所有任务”以返回完整的、未过滤的列表),经过大量的试验和错误(创建不再正确绑定的过滤数组等)。等)我尝试过这个,基本上只使用原始数组。
List {
ForEach(project.tasks.filter({ $0.phase.contains(filterValue) }).indices, id: \.self) { idx in
HStack {
Text(project.tasks[idx].phase)
.font(.caption)
Spacer()
Text(project.tasks[idx].name)
Spacer()
Toggle("", isOn: self.$project.tasks[idx].isComplete)
}
}
}
Run Code Online (Sandbox Code Playgroud)
当然,这似乎有效,因为我可以做一个测试:
func CreateTestArray() {
let testFilterArray = project.tasks.filter({ $0.phase.contains(filterValue) …
Run Code Online (Sandbox Code Playgroud) 假设我们有matrix
一个这样的:
# Set seed
set.seed(12345)
# Generate data.frame
df <- matrix(sample(1:100,100), nrow = 10)
Run Code Online (Sandbox Code Playgroud)
我想获取第一个最高值所在的行和列n
。
我知道使用which(df == max(df), arr.ind=TRUE)
我可以得到我想要的东西,但只是为了获得最高的价值。
假设我们想要矩阵中 5 个最高值的位置。根据之前的答案,我尝试过,which(aux %in% sort(df, decreasing=T)[1:5], arr.ind = TRUE)
但没有成功。
我还知道,使用 order(df, decreasing=T)
和调制结果可以得到我正在寻找的行和列。尽管如此,我认为这应该是获得它的最快方法。
提前谢谢你的帮助
indices ×10
arrays ×3
python ×3
r ×2
data-science ×1
data.table ×1
filter ×1
highest ×1
iphone ×1
list ×1
matrix ×1
max ×1
numpy ×1
objective-c ×1
opengl ×1
opengl-es ×1
pytorch ×1
random ×1
sql ×1
sql-server ×1
swiftui ×1
vertex-array ×1
xcode ×1