[Numpy-discussion] 2D array to 3D

Robert Kern robert.kern at gmail.com
Sat Apr 26 05:24:58 EDT 2008


2008/4/25 tournesol <tournesol33 at gmail.com>:
> Hi All.
>
>  Is there a easy way to insert 1D(j) array into another 2D array(B:jxk)
>  and conver B to B:ixjxk ?
>
>  ex:)
>
>  >>> from numpy import *
>  >>> a=arange(4)
>  >>> a
>  array([0, 1, 2, 3])
>  >>> b=arange(9)
>  >>> b.shape=3,3
>  >>> b
>  array([[0, 1, 2],
>  [3, 4, 5],
>  [6, 7, 8]])
>
>  I just wanna insert A into B
>  B:1x3x3,
>
>  [[[ 0, 1, 2, 3],
>  [ 4, 5, 6, 7],
>  [ 8, 9, 10, 11]]
>
>
>  B:2x3x3,
>
>  [[[ 0, 1, 2, 3],
>  [ 4, 5, 6, 7],
>  [ 8, 9, 10, 11]]
>
>  [[ 0, 1, 2, 3],
>  [ 4, 5, 6, 7],
>  [ 8, 9, 10, 11]]]
>
>  B:3x3x3,
>  [[[ 0, 1, 2, 3],
>  [ 4, 5, 6, 7],
>  [ 8, 9, 10, 11]]
>
>  [[ 0, 1, 2, 3],
>  [ 4, 5, 6, 7],
>  [ 8, 9, 10, 11]]
>
>  [[ 0, 1, 2, 3],
>  [ 4, 5, 6, 7],
>  [ 8, 9, 10, 11]]]

I'm sorry, but I cannot understand what you are asking for.

-- 
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



More information about the NumPy-Discussion mailing list