[SciPy-User] [scipy-user] How to add a 1D np.array to another np.array?
Warren Weckesser
warren.weckesser at enthought.com
Wed Feb 1 11:35:25 EST 2012
On Wed, Feb 1, 2012 at 10:21 AM, Fabien Lafont <lafont.fabien at gmail.com>wrote:
> Hello everyone,
>
> I try to add an array to another (to build a 2D array).
>
> I try that
>
>
>
> a = np.zeros(2)
> b=np.array([2,4])
> a[[0]] = b
>
> print a
> [2,0]
>
> And I want a= [[2,4],0]
>
>
But that is not a 2D array. Do you want to "stack" b above the zeros?
Perhaps something like this:
In [7]: a = np.zeros(2)
In [8]: b = np.array([2,4])
In [9]: c = np.vstack((b,a))
In [10]: c
Out[10]:
array([[ 2., 4.],
[ 0., 0.]])
Warren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20120201/66c71c74/attachment.html>
More information about the SciPy-User
mailing list