[SciPy-User] [scipy-user] How to add a 1D np.array to another np.array?

Fabien Lafont lafont.fabien@gmail....
Thu Feb 2 02:34:42 CST 2012


In fact I would prefer, replace the first 0 by [2,4] but it still
interesting, thx!

Fabien

2012/2/1 Warren Weckesser <warren.weckesser@enthought.com>:
>
>
> On Wed, Feb 1, 2012 at 10:21 AM, Fabien Lafont <lafont.fabien@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
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list