Array storage in python
I want to store a bunch of arrays for future use, how can I do this in python? I usually use 开发者_运维问答 append() method for element storage but this doesn't work with arrays.
Thanks.
Why are you using arrays? Do you mean lists? if your using lists then you can append lists (objects) anything to other lists.
If you talk about numpy arrays: either you append the elements to a list and construct an array from this list via numpy.array(li)
or you use numpys hstack()
resp. vstack()
.
Numpy does provide an append
function. The usage example given in the numpy documentation:
>>> from numpy import *
>>> a = array([10,20,30,40])
>>> append(a,50)
array([10, 20, 30, 40, 50])
>>> append(a,[50,60])
array([10, 20, 30, 40, 50, 60])
>>> a = array([[10,20,30],[40,50,60],[70,80,90]])
>>> append(a,[[15,15,15]],axis=0)
array([[10, 20, 30],
[40, 50, 60],
[70, 80, 90],
[15, 15, 15]])
>>> append(a,[[15],[15],[15]],axis=1)
array([[10, 20, 30, 15],
[40, 50, 60, 15],
[70, 80, 90, 15]])
精彩评论