【发布时间】:2011-11-05 08:47:48
【问题描述】:
我在 NumPy 和 ndarray 的自定义 dtype 中发现了以下令人费解的行为:
import numpy as np
# Make a custom dtype with a single triplet of floats (my actual dtype has other
# components, but this suffices to demonstrate the problem.
dt = np.dtype([('a', np.float64, 3)])
# Make a zero array with this dtype:
points = np.zeros((4, 4), dtype=dt)
# Try to edit an entry:
points[0][0]['a'] = np.array([1, 1, 1])
print points[0][0]['a']
现在,这返回为不包含 [1。 1. 1.] 正如我所期望的那样,而是 [1. 0. 0.],只对第一个坐标进行赋值。我可以通过按坐标执行分配来解决这个问题,但考虑到在这种情况下完全分配肯定应该是默认行为,这似乎是不必要的。
对这里发生的事情有什么想法吗?
【问题讨论】:
标签: python arrays multidimensional-array numpy