[Numpy-discussion] array manupulation

Sudheer Joseph sudheer.joseph at yahoo.com
Sun May 26 06:55:47 EDT 2013


Thank you Aronne for the helping hand,
                                      I tried the transpose as a check when I could not get it correct other way. I could do it with test arrays, but it appears some thing strange happens when I do the cumsum. So I am attaching here the csum as csum.npy array, where I face problem if your time permits please see what happens with this strange array.!


In [1]: csum=np.load('csum.npy') should get the array to you.

This  array is obtained by doing a 
csum=np.cumsum(prcnt), which apparently doing some thing which I am not able to visualize.

with best regards,
Sudheer.

>From:Aronne Merrelli <aronne.merrelli at gmail.com>
>To:Discussion of Numerical Python <numpy-discussion at scipy.org> 
>Sent:Sunday, 26 May 2013 2:13 PM
>Subject:Re: [Numpy-discussion] array manupulation
> 
>
>
>
>
>On Sun, May 26, 2013 at 4:30 AM, Sudheer Joseph <sudheer.joseph at yahoo.com> wrote:
>
>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
>>
>>  
>>
>
>
>You've transposed the arrays, so now you need to stack the other way. So, you need to use hstack to concatenate arrays with the same column length (first axis), or vstack to concatenate arrays with the same row length (second axis). For example:
>
>
>In [110]: xx1 = np.zeros((1,7)); cc1 = np.ones((3,7))
>
>
>In [111]: xx2 = np.zeros((7,1)); cc2 = np.ones((7,3))
>
>
>In [112]: np.vstack((xx1, cc1))
>Out[112]: 
>array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
>       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
>       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.]])
>
>
>In [113]: np.hstack((xx2, cc2))
>Out[113]: 
>array([[ 0.,  1.,  1.,  1.],
>       [ 0.,  1.,  1.,  1.],
>       [ 0.,  1.,  1.,  1.],
>       [ 0.,  1.,  1.,  1.],
>       [ 0.,  1.,  1.,  1.],
>       [ 0.,  1.,  1.,  1.],
>       [ 0.,  1.,  1.,  1.]])
>
>
>
>
>Also, I would highly recommend studying the NumPy for MATLAB users guide:
>
>
>http://www.scipy.org/NumPy_for_Matlab_Users
>
>
>
>These issues (any many more) are discussed there.
>
>
>
>
>Cheers,
>Aronne
>_______________________________________________
>NumPy-Discussion mailing list
>NumPy-Discussion at scipy.org
>http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: csum.npy
Type: application/octet-stream
Size: 520 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130526/72ef627a/attachment.obj>


More information about the NumPy-Discussion mailing list