[Tutor] dynamic arrays?

Joel Levine Joel.Levine at Dartmouth.EDU
Mon Sep 27 20:34:05 CEST 2010


I'm guessing you are also using numpy and that you want arrays (or matrices) for  
the sake of either (a) matrix and array functions or (b) much greater processing  
speed.

Add
from numpy import *

Then hat you can do is go back and forth:  Build what you intend to be an array,  
but build it as a list using append.

then ar=array(list)

converts it.

If you want to change its size again, convert it back to a list, change it, convert  
it back to an array.

The functions you need are list(), array(), and possibly matrix()


>>>  from numpy import *
>>>  a=[1,2,3]
>>>  type(a)
<type 'list'>
>>>  ar=array(a)
>>>  ar
array([1, 2, 3])
>>>  matrix(ar)
matrix([[1, 2, 3]])
>>>  type(ar)
<type 'numpy.ndarray'>
>>>  


More information about the Tutor mailing list