array manipulation
![](https://secure.gravatar.com/avatar/612395b66b3e7959997007b342b3688a.jpg?s=120&d=mm&r=g)
Hi all, How can I insert a row/column in an existing array ? Nils
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
On Wed, Nov 19, 2008 at 01:32, Nils Wagner <nwagner@iam.uni-stuttgart.de> wrote:
Hi all,
How can I insert a row/column in an existing array ?
You can't. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
![](https://secure.gravatar.com/avatar/4049498c84d4a7a8f5f5afa5b86c4d2b.jpg?s=120&d=mm&r=g)
Robert Kern a écrit :
On Wed, Nov 19, 2008 at 01:32, Nils Wagner <nwagner@iam.uni-stuttgart.de> wrote:
Hi all,
How can I insert a row/column in an existing array ?
You can't. And numpy.insert?
Return a new array with values inserted along the given axis before the given indices If axis is None, then ravel the array first. The obj argument can be an integer, a slice, or a sequence of integers. Examples -------- >>> a = array([[1,2,3], ... [4,5,6], ... [7,8,9]]) >>> insert(a, [1,2], [[4],[5]], axis=0) array([[1, 2, 3], [4, 4, 4], [4, 5, 6], [5, 5, 5], [7, 8, 9]]) Cheers, -- Fred
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
On Wed, Nov 19, 2008 at 01:53, fred <fredmfp@gmail.com> wrote:
Robert Kern a écrit :
On Wed, Nov 19, 2008 at 01:32, Nils Wagner <nwagner@iam.uni-stuttgart.de> wrote:
Hi all,
How can I insert a row/column in an existing array ?
You can't. And numpy.insert?
Return a new array with values inserted along the given axis before the given indices
I assumed that by "existing array," he didn't want "a new array." -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
![](https://secure.gravatar.com/avatar/612395b66b3e7959997007b342b3688a.jpg?s=120&d=mm&r=g)
On Wed, 19 Nov 2008 01:39:34 -0600 "Robert Kern" <robert.kern@gmail.com> wrote:
On Wed, Nov 19, 2008 at 01:32, Nils Wagner <nwagner@iam.uni-stuttgart.de> wrote:
Hi all,
How can I insert a row/column in an existing array ?
You can't.
How about that ?
A = ones((10,5)) A array([[ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.]]) A=insert(A,[1],20,axis=1) A array([[ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.], [ 1., 20., 1., 1., 1., 1.]]) A[:,1] = random.rand(10)
Nils
participants (3)
-
fred
-
Nils Wagner
-
Robert Kern