>>> a = [[1,2,3],[4,5,6],[7,8,9]]
>>> print a
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> b = a.pop(1)
>>> print a
[[1, 2, 3], [7, 8, 9]]
>>> print b
[4, 5, 6]
>>> from numpy import array
>>> a = array([[1,2,3],[4,5,6],[7,8,9]])
>>> print a
[[1 2 3]
[4 5 6]
[7 8 9]]
>>> b = a.pop(1)
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
b = a.pop(1)
AttributeError: 'numpy.ndarray' object has no attribute 'pop'
>>>
So, what's the "right" way of doing this in numpy?
Armando.
_______________________________________________
SciPy-user mailing list
SciPy...@scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user
It seems that you do not really want an ndarray.
Maybe a Python array would do.
Or maybe you are trying to do something that does
not really require a ``pop`` ...
Cheers,
Alan Isaac
> Hello:
>
>>>> a = [[1,2,3],[4,5,6],[7,8,9]]
>>>> print a
> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>>> b = a.pop(1)
>>>> print a
> [[1, 2, 3], [7, 8, 9]]
>>>> print b
> [4, 5, 6]
>>>> from numpy import array
>>>> a = array([[1,2,3],[4,5,6],[7,8,9]])
>>>> print a
> [[1 2 3]
> [4 5 6]
> [7 8 9]]
>>>> b = a.pop(1)
>
> Traceback (most recent call last):
> File "<pyshell#14>", line 1, in <module>
> b = a.pop(1)
> AttributeError: 'numpy.ndarray' object has no attribute 'pop'
>>>>
>
> So, what's the "right" way of doing this in numpy?
The closest thing I can come up with, is
In [1]: from numpy import *
In [2]: a = array([[1,2,3],[4,5,6],[7,8,9]])
In [3]: b = a[1]
In [4]: a = delete(a,[1], axis=0)
but this introduces quite some overhead, so, as Alan said, ask
yourself whether this is really what you need.
Joris
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm