deleting value from array
I am trying to delete a value from an array This seems to work as follows
a = array([1,2,3,4]) a = delete( a, 1 ) a array([1, 3, 4])
But wouldn't it make more sense to have a function like a.delete(1) ? I now get the feeling the delete command needs to copy the entire array with exception of the deleted item. I guess this is a hard thing to do efficiently? Thanks, Mark
Yeah, I can see the copying is essential. I just think the syntax a = delete(a,1) confusing, as I would expect the deleted value back, rather than the updated array. As in the 'pop' function for lists. No 'pop' in numpy? (I presume this may have been debated extensively in the past). I find the syntax a.delete(1) more logical. Mark On Aug 15, 11:19 am, "Matthieu Brucher" <matthieu.bruc...@gmail.com> wrote:
I now get the feeling the delete command needs to copy the entire array with exception of the deleted item. I guess this is a hard thing to do efficiently?
Well, if you don't copy the array, the value will always remain present.
Matthieu
_______________________________________________ Numpy-discussion mailing list Numpy-discuss...@scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion
On Wed, Aug 15, 2007 at 03:11:59AM -0700, mark wrote:
Yeah, I can see the copying is essential. I just think the syntax a = delete(a,1) confusing, as I would expect the deleted value back, rather than the updated array. As in the 'pop' function for lists. No 'pop' in numpy? (I presume this may have been debated extensively in the past). I find the syntax a.delete(1) more logical.
It is often considered in OO language that foo.method() modifies the foo object, while function(foo) returns a new object, not modifying foo. This is not always true in Python. Sometimes (eg strings) this is not true because the object is immutable, sometimes there isn't this good reason. I would be happy if we sticked to this convention. I find it makes the language easier to guess. Gaël
The closest I can think of is: a = a[range(len(a)) != 1] Nadav. On Wed, 2007-08-15 at 02:07 -0700, mark wrote:
I am trying to delete a value from an array This seems to work as follows
a = array([1,2,3,4]) a = delete( a, 1 ) a array([1, 3, 4])
But wouldn't it make more sense to have a function like
a.delete(1) ?
I now get the feeling the delete command needs to copy the entire array with exception of the deleted item. I guess this is a hard thing to do efficiently?
Thanks,
Mark
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
participants (4)
-
Gael Varoquaux -
mark -
Matthieu Brucher -
Nadav Horesh