[Numpy-discussion] Creating array containing empty lists

Jesper Larsen jesper.webmail@gmail....
Wed Mar 25 06:04:43 CDT 2009


Hi numpy people,

I have a problem with array broadcasting for object arrays and list. I
would like to create a numpy array containing empty lists (initially -
I will append to them later):

import numpy as npy
a = npy.empty((2), dtype=npy.object_)

# Works fine:
for i in range(len(a)):
  a[i] = []
print a

# Does not work:
a[:] = []
a[:] = list()

Is it possible to broadcast a list to all elements of a numpy array?
Or will I have to loop through it and set the individual elements?

Best regards,
Jesper


More information about the Numpy-discussion mailing list