In [18]: a = np.empty((2,3),dtype=int)

In [19]: a
Out[19]:
array([[31064454,        0, 41579024],
       [       0, 30625104,        0]])

In [20]: a[0,2]
Out[20]: 41579024

In [21]: a[1,1]
Out[21]: 30625104

只对某行、列求和

Here is an example of the sum function:

In [11]: a.sum()
Out[11]: 95

In their default form, these functions "flatten" the array and aggregate over all elements. You can specify an optional axis in order to perform the reduction over rows or columns, in the case of a 2D array. Providing axis 0 does the reduction over columns:

In [13]: a.mean(0)
Out[13]: array([ 1.8,  6.2,  2.2,  4.2,  4.6])

...and providing axis 1 does the reduction over rows:

In [14]: a.mean(1)
Out[14]: array([ 1. ,  3.6,  3.6,  5.4,  5.4])

results matching ""

    No results matching ""