Re: clean way prepend an element to a numpy array

2009-07-24 Thread Robert Kern
On 2009-07-24 18:26, greg wrote: Robert Kern wrote: a[:0] = array('i', [0]) Not when 'a' is a numpy array rather than an array.array. That's true, but I got the impression that the OP was talking about array.array, not numpy.array. Did you read the Subject: line? :-) -- Robert Kern "I h

Re: clean way prepend an element to a numpy array

2009-07-24 Thread greg
Robert Kern wrote: a[:0] = array('i', [0]) Not when 'a' is a numpy array rather than an array.array. That's true, but I got the impression that the OP was talking about array.array, not numpy.array. It's very confusing having two widely-used types both called 'array'. :-( -- Greg -- http:/

Re: clean way prepend an element to a numpy array

2009-07-22 Thread Robert Kern
On 2009-07-22 01:51, greg wrote: bdb112 wrote: I saw this interest syntax on this site x[:0]=0 I guess that is cute, but could be confusing(and doesn't work) It does if you use an array of the appropriate type on the right hand side: a[:0] = array('i', [0]) Not when 'a' is a numpy arr

Re: clean way prepend an element to a numpy array

2009-07-21 Thread greg
bdb112 wrote: I saw this interest syntax on this site x[:0]=0 I guess that is cute, but could be confusing(and doesn't work) It does if you use an array of the appropriate type on the right hand side: a[:0] = array('i', [0]) -- Greg -- http://mail.python.org/mailman/listinfo/python-li

Re: clean way prepend an element to a numpy array

2009-07-21 Thread Robert Kern
On 2009-07-20 22:56, bdb112 wrote: If I want to add an element at the beginning of an array, it seems like I must make a list, insert in place, then make an array again. the_array = numpy.concatenate([new_value, the_array]) You will want to ask numpy questions on the numpy mailing list. htt

Re: clean way prepend an element to a numpy array

2009-07-20 Thread bdb112
On Jul 21, 2:13 pm, Ben Finney wrote: > bdb112 writes: > > If I want to add an element at the beginning of an array, it seems > > like I must make a list, insert in place, then make an array again. > > The NumPy ‘ndarray’ type (which is what you get by default from the > ‘array’ factory function)

Re: clean way prepend an element to a numpy array

2009-07-20 Thread Ben Finney
bdb112 writes: > If I want to add an element at the beginning of an array, it seems > like I must make a list, insert in place, then make an array again. The NumPy ‘ndarray’ type (which is what you get by default from the ‘array’ factory function) is a far more complex type than (and is not deri