Building up an array in numpy/scipy by iteration in Python?

Posted by user248237 on Stack Overflow See other posts from Stack Overflow or by user248237
Published on 2010-04-14T23:13:33Z Indexed on 2010/04/14 23:43 UTC
Read the original article Hit count: 134

Filed under:
|
|

Often, I am building an array by iterating through some data, e.g.:

my_array = []
for n in range(1000):
  # do operation, get value 
  my_array.append(value)
# cast to array
my_array = array(my_array)

I find that I have to first build a list and then cast it (using "array") to an array. Is there a way around these? all these casting calls clutter the code... how can I iteratively build up "my_array", with it being an array from the start? thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy