[Numpy-discussion] array manupulation
Sudheer Joseph
sudheer.joseph at yahoo.com
Sat May 25 22:30:24 EDT 2013
Dear Brian,
I even tried below but no luck!
In [138]: xx=np.zeros(11)
In [139]: xx
Out[139]: array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
In [147]: xx.shape
Out[147]: (11,)
In [140]: xx=np.array(xx)[np.newaxis]
In [141]: xx.shape
Out[141]: (1, 11)
In [142]: xx=xx.T
In [143]: xx.shape
Out[143]: (11, 1)
In [144]: csum.shape
Out[144]: (11, 5)
In [145]: np.vstack((xx,csum))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/media/SJOITB/SST_VAL/<ipython-input-145-2a0a60f68737> in <module>()
----> 1 np.vstack((xx,csum))
/usr/local/lib/python2.7/dist-packages/numpy-1.7.0-py2.7-linux-x86_64.egg/numpy/core/shape_base.pyc in vstack(tup)
224
225 """
--> 226 return _nx.concatenate(map(atleast_2d,tup),0)
227
228 def hstack(tup):
ValueError: all the input array dimensions except for the concatenation axis must match exactly
***************************************************************
Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India at gmail.com;sudheer.joseph at yahoo.com
Web- http://oppamthadathil.tripod.com
***************************************************************
----- Original Message -----
> From: Sudheer Joseph <sudheer.joseph at yahoo.com>
> To: Discussion of Numerical Python <numpy-discussion at scipy.org>
> Cc:
> Sent: Sunday, 26 May 2013 6:25 AM
> Subject: Re: [Numpy-discussion] array manupulation
>
>T hank you Brian,
> Though the simple example worked for me, there appears to
> the some logic which I did not capture fully.
>
> I have a 11x5 array named p from which I get a cumulative sum by doing below
> operations. I tried transposing the zero array to match the dimension( after
> first failed) but had no luck. It appears I am missing some change happening
> when I take the cumulative sum along newaxis. Can you please advice me on what I
> am missing here?
>
> Out[84]:p.shape
> Out[85]: (11, 5)
> c=p.cumsum(axis=0)
>
> In [86]: c.shape
> Out[86]: (11, 5)
> In [87]: xx=np.zeros(11)
> In [88]: xx
>
> Out[88]: array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
> np.vstack((xx,c))
>
> ---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
> /media/SJOITB/SST_VAL/<ipython-input-89-b81a9a48bb54> in <module>()
> ----> 1 np.vstack((xx,c))
>
> /usr/local/lib/python2.7/dist-packages/numpy-1.7.0-py2.7-linux-x86_64.egg/numpy/core/shape_base.pyc
> in vstack(tup)
> 224
> 225 """
> --> 226 return _nx.concatenate(map(atleast_2d,tup),0)
> 227
> 228 def hstack(tup):
>
> ValueError: all the input array dimensions except for the concatenation axis
> must match exactly
>
>
> ----- Original Message -----
>> From: Bryan Van de Ven <bryanv at continuum.io>
>> To: Discussion of Numerical Python <numpy-discussion at scipy.org>
>> Cc:
>> Sent: Saturday, 25 May 2013 11:54 PM
>> Subject: Re: [Numpy-discussion] array manupulation
>>
>> I'm not sure what you tried, but stack will do what you are seeking:
>>
>> In [7]: cc = np.ones((2,10)) * np.arange(1, 11)
>>
>> In [8]: cc
>> Out[8]:
>> array([[ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.],
>> [ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]])
>>
>> In [9]: np.vstack((np.zeros(10), cc))
>> Out[9]:
>> array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
>> [ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.],
>> [ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]])
>>
>> Bryan
>>
>>
>> On May 25, 2013, at 7:19 AM, Sudheer Joseph
> <sudheer.joseph at yahoo.com>
>> wrote:
>>
>>> Dear experts,
>>> I can do below operation in matlab but I wanted to do the same in
> python
>> numpy array.
>>> I tried np.vstak and np.concatenate but not getting the desired
> results.
>> please help. I wanted to add a row of zeros to the beginning of a numpy
> array.
>> What is the available quick way.
>>>
>>>>> cc=[1:10;1:10]
>>>
>>> cc =
>>> 1 2 3 4 5 6 7 8 9 10
>>> 1 2 3 4 5 6 7 8 9 10
>>>>> cc=[cc(1,:)*0;cc]
>>> cc =
>>> 0 0 0 0 0 0 0 0 0 0
>>> 1 2 3 4 5 6 7 8 9 10
>>> 1 2 3 4 5 6 7 8 9 10
>>>
>>> wit best regards,
>>> Sudheer
>>> ***************************************************************
>>> Sudheer Joseph
>>> Indian National Centre for Ocean Information Services
>>> Ministry of Earth Sciences, Govt. of India
>>> POST BOX NO: 21, IDA Jeedeemetla P.O.
>>> Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
>>> Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
>>> Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
>>> E-mail:sjo.India at gmail.com;sudheer.joseph at yahoo.com
>>> Web- http://oppamthadathil.tripod.com
>>> ***************************************************************
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list