与对象数组numpy的 [英] Objects array with numpy
本文介绍了与对象数组numpy的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请问有什么方法来创建一个对象形成一个numpy的数组中任何一类?是这样的:
are there any way to create an object form any class inside a numpy array?. Something like:
a = zeros(4)
for i in range(4):
a[i]=Register()
感谢
推荐答案
是的,你可以这样做:
a = numpy.array([Register() for _ in range(4)])
在这里, a.dtype
是 DTYPE('对象')
。
另外,如果你真的需要保留内存阵列,然后通过元素构建它的元素,你可以这样做:
Alternatively, if you really need to reserve memory for your array and then build it element by element, you can do:
a = numpy.empty(shape=(4,), dtype=object)
a[0] = Register() # etc.
这篇关于与对象数组numpy的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文