我是 python 新手,我正在使用 IPython,我开始了解 NetworkX,但现在只是在起点,我注意到 networkx.draw() 不起作用,这是我的代码:
import networkx as nx
g = nx.Graph()
g.add_nodes_from([1,2,3,4])
nx.draw(g)
Run Code Online (Sandbox Code Playgroud)
但什么也没画!
在适用于Android的OpenGL ES 1中,我有一个Rubic多维数据集,其中包含27个较小的多维数据集。我想要旋转,使特定的小立方体正好位于视点的前面。所以我需要两个向量 一个是从对象原点到特定立方体的向量。另一个是从原点到视点的向量。然后它们的叉积给我旋转轴,点积给我角度。
我将(0,0,1)(这是从原点到世界坐标中的视点的向量)转换为对象坐标。这是代码:
matrixGrabber.getCurrentModelView(gl);
temporaryMatrix.set(matrixGrabber.mModelView);
inputVector[0] = 0f;
inputVector[1] = 0f;
inputVector[2] = 1f;
inputVector[3] = 1f;
Matrix.multiplyMV(resultVector, 0, temporaryMatrix.InvertMatrix(), 0, inputVector,0);
resultVector[0]/=resultVector[3];
resultVector[1]/=resultVector[3];
resultVector[2]/=resultVector[3];
inputVector = ..... // appropriate vector due to user-selection
axis = Vector.normalized(Vector.crossProduct(Vector.normalized(inputVector), Vector.normalized(resultVector)));
degree = (float)Math.toDegrees(Math.acos(Vector.dot(Vector.normalized(inputVector), Vector.normalized(resultVector))));
Run Code Online (Sandbox Code Playgroud)
我使用两个四元数进行旋转。每次用户选择一个动作时,都会发生一种轮换。这是代码:
Quaternion currentRotation = new Quaternion();
Quaternion temporaryRotation = new Quaternion();
.
.
.
currentRotation = (currentRotation).mulLeft(temporaryRotation.set(axis, degree));
currentRotation.toMatrix(matrix);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glMultMatrixf(matrix, 0);
Run Code Online (Sandbox Code Playgroud)
现在的问题是,它在第一次旋转时效果很好。不管第一次旋转。它运作良好,但是对于下一个旋转,它似乎得到了错误的轴和度。
例如,如果坐标系为
然后首先绕逆时针(CCW)旋转X 90度产生
第二次绕Z 90度逆时针旋转产生
我有一个文本文件,其中包含一些波斯文本,我想读取文件并计算每个单词的出现次数,然后打印计算值.这是我的代码:
f = open('C:/python programs/hafez.txt')
wordDict ={}
for line in f:
wordList = line.strip().split(' ')
for word in wordList:
if word not in wordDict:
wordDict[word] = 1
else: wordDict[word] = wordDict[word]+1
print((str(wordDict)))
Run Code Online (Sandbox Code Playgroud)
它产生的结果具有错误的编码格式,我尝试了各种方法来解决这个问题但没有好结果!以下是此代码生成的文本的一部分:
{"\ x00'\ x063\x06(\ x06":3,"\ x00,\ x06'\ x06E\x06G\x06":16,"\ x00'\ x063\x06*\x06E\x06'\ x069\x06":1,'\ x00-\x064\x061\x06':1,.....}
我有一个边缘列表,它由两列组成,我想创建一个加权有向图,以便对于边缘列表中的每一行,权重为1的有向边缘从第一列的节点到第二列的节点。如果同一行在边缘列表中出现多次,则每次出现时应将权重增加一。
我正在使用Python Networkx库如何执行此操作?