Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想对一个多维数组进行赋值,其中数组的每个元素都是 3 个短整数:
a = ndarray([3,3,3], dtype='u2,u2,u2') a[2,2,2] = [1,2,3]
Traceback(最近一次调用最后一次):文件“”,第 1 行,在 a[2,2,2] = [1,2,3] 类型错误:期望一个可读的缓冲区对象
我将使用一个大数组,并希望直接索引到数组中以提高性能。在 python 中执行此操作的好方法是什么?
感谢您提供有关如何执行此操作的任何见解?
数组的元素是三个短裤dtype='u2,u2,u2'的元组,而不是三个短裤的列表。所以:
dtype='u2,u2,u2'
a[2,2,2] = (1,2,3)
(括号当然不是必需的,但我用它们来表明这是一个元组。)
array如果你愿意,你也可以通过它:
array
a[2,2,2] = np.array([1,2,3])
当然,这里的错误消息肯定会更好……它实际上抱怨的东西比你预期的更深,它并不能帮助你调试问题。