[Numpy-discussion] array manupulation
Olivier Delalleau
shish at keba.be
Sun May 26 17:52:13 EDT 2013
Your array doesn't seem strange, it looks like a perfectly normal (11 x 5)
matrix of dtype float64.
>>> x = np.load('csum.npy')
>>> np.vstack((np.zeros((1, x.shape[1])), x))
array([[ 0. , 0. , 0. , 0. ,
0. ],
[ 31.82571459, 29.0629995 , 27.74400711, 26.6248159 ,
25.73787976],
[ 59.82231014, 54.27656749, 51.87813602, 50.00937323,
48.51771275],
[ 80.03460893, 73.46862838, 70.55710765, 68.412796 ,
66.64323907],
[ 91.12613011, 85.96434025, 83.34633829, 81.36538282,
79.70197141],
[ 96.11498624, 93.00049572, 91.13864656, 89.61535722,
88.27247424],
[ 98.22403322, 96.55379518, 95.43277035, 94.39550817,
93.42804 ],
[ 99.14200421, 98.27546395, 97.64792507, 97.00438205,
96.3689249 ],
[ 99.55954577, 99.10418687, 98.76971791, 98.39724171,
98.00386825],
[ 99.76081882, 99.51702755, 99.33960611, 99.13057243,
98.9007987 ],
[ 99.8617198 , 99.72882047, 99.63273748, 99.51539561,
99.38460995],
[ 100. , 100. , 100. , 100. ,
100. ]])
-=- Olivier
2013/5/26 Sudheer Joseph <sudheer.joseph at yahoo.com>
> 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
> >
> >
> >
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130526/bb5e4555/attachment.html>
More information about the NumPy-Discussion
mailing list