开发者

Doing column math with numpy in python

I am looking for coding examples to learn Numpy.

Usage would be dtyp开发者_开发百科e ='object'. To construnct array the code used would

a= np.asarray(d, dtype ='object')

not np.asarray(d) or np.asarray(d, dtype='float32')

Is sorting any different than float32/64?

Coming from excel "cell" equations, wrapping my head around Row Column math.

Ex:

A = array([['a',2,3,4],['b',5,6,2],['c',5,1,5]], dtype ='object')

[['a',2,3,4],
 ['b',5,6,2],
 ['c',5,1,5]])

Create new array with: How would I sort high to low by [3].

How calc for entire col. (1,1)- (1,0), Example without sorting A

 ['b',3],
 ['c',0]

How calc for enitre array (1,1) - (2,0) Example without sorting A

 ['b',2],
 ['c',-1]


Despite the fact that I still cannot understand exactly what you are asking, here is my best guess. Let's say you want to sort A by the values in 3rd column:

A = array([['a',2,3,4],['b',5,6,2],['c',5,1,5]], dtype ='object')

ii = np.argsort(A[:,2])
print A[ii,:]

Here the rows have been sorted according to the 3rd column, but each row is left unsorted.

Subtracting all of the columns is a problem due to the string objects, however if you exclude them, you can for example subtract the 3rd row from the 1st by:

A[0,1:] - A[2,1:]

If I didn't understand the basic point of your question, then please revise it. I highly recommend you take a look at the numpy tutorial and documentation if you have not done so already:

http://docs.scipy.org/doc/numpy/reference/

http://docs.scipy.org/doc/numpy/user/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜