I want to create an array with dtype=np.object
, where each element is an array with a numerical type, e.g int or float. For example:
>>>
I can't find any elegant solution, but at least a more general solution to doing everything by hand is to declare a function of the form:
def object_array(*args):
array = np.empty(len(args), dtype=np.object)
for i in range(len(args)):
array[i] = args[i]
return array
I can then do:
a = np.array([1,2,3])
b = object_array(a,a,a)
I then get:
>>> a = np.array([1,2,3])
>>> b = object_array(a,a,a)
>>> print b.dtype
object
>>> print b.shape
(3,)
>>> print b[0].dtype
int64