我有两个 numpy 数组 A 和 B。A 的形状是 (m,3),B 的形状是 (n, 3)。
这些矩阵看起来像这样:
A
#output
array([[ 9.227, -4.698, -95.607],
[ 10.294, -4.659, -94.606],
[ 11.184, -5.906, -94.675],
...,
[ 19.538, -91.572, -45.361],
[ 20.001, -92.655, -45.009],
[ 19.271, -92.726, -45.79 ]])
Run Code Online (Sandbox Code Playgroud)
所以它包含每一行的坐标 x,y,z 一个 3D 点。B 遵循相同的格式。
我有这个功能(np 是 numpy):
def compute_dist(point1, point2):
squared = (point1-point2)**2
return (np.sqrt(np.sum(squares)))
Run Code Online (Sandbox Code Playgroud)
我想使用矢量化函数计算 A 和 B 之间的成对距离。
我试试这个:
v = np.vectorize(compute_dist)
v(A, B)
#output
matrix([[37.442, 42.693, 72.705],
[37.442, 42.693, 72.705],
[37.442, 42.693, 72.705],
...,
[37.442, …Run Code Online (Sandbox Code Playgroud) 我正在开发Unity。我创建线作为名为“ out100”的游戏对象的子代。我可以用鼠标滚动单击来移动该游戏对象,右键单击来旋转它等。但是,只有我的游戏对象“ out100”在移动,而不是我的线。
foreach (KeyValuePair<string, List<Vector3>> sl in d) {
Color c1 = Color.yellow;
Color c2 = Color.red;
GameObject lines = new GameObject ();
lines.name = "lines" + sl.Key;
lines.AddComponent<LineRenderer> ();
lines.transform.SetParent (GameObject.Find ("out100").transform);
LineRenderer lineRenderer = lines.GetComponent<LineRenderer> ();
lineRenderer.material = new Material (Shader.Find ("Particles/Additive"));
lineRenderer.widthMultiplier = 0.2f;
lineRenderer.positionCount = sl.Value.Count;
float alpha = 1.0f;
Gradient gradient = new Gradient ();
gradient.SetKeys (
new GradientColorKey[] { new GradientColorKey (c1, 0.0f), new GradientColorKey (c2, 1.0f) },
new GradientAlphaKey[] { new GradientAlphaKey …Run Code Online (Sandbox Code Playgroud)