numpy.sum(arr, axis, dtype, out) : Ta funkcija vrne vsoto elementov matrike na določeni osi.
Parametri:
prihod: vhodno polje.
os: os, vzdolž katere želimo izračunati vrednost vsote. V nasprotnem primeru bo menil, da je arr sploščen (deluje na vseh osih). os = 0 pomeni vzdolž stolpca in os = 1 pomeni delo vzdolž vrstice.
ven: Drugačna matrika, v katero želimo umestiti rezultat. Matrika mora imeti enake dimenzije kot pričakovani izhod. Privzeto je Brez.
začetnica: [skalar, neobvezno] Začetna vrednost vsote.
Povratek: Vsota elementov matrike (skalarna vrednost, če os ni nobena) ali matrika z vsoto vrednosti vzdolž podane osi.
Koda #1:
java je naslednja
Python3
# Python Program illustrating> # numpy.sum() method> import> numpy as np> > # 1D array> arr> => [> 20> ,> 2> , .> 2> ,> 10> ,> 4> ]> > print> ('
Sum of arr : ', np.> sum> (arr))> > print> ('> Sum> of arr(uint8) : ', np.> sum> (arr, dtype> => np.uint8))> print> ('> Sum> of arr(float32) : ', np.> sum> (arr, dtype> => np.float32))> > print> ('
Is np.> sum> (arr).dtype> => => np.uint : ',> > np.> sum> (arr).dtype> => => np.uint)> print> ('Is np.> sum> (arr).dtype> => => np.> float> : ',> > np.> sum> (arr).dtype> => => np.> float> )> |
>
>
Izhod:
posodobitev iz join sql
Sum of arr : 36.2 Sum of arr(uint8) : 36 Sum of arr(float32) : 36.2 Is np.sum(arr).dtype == np.uint : False Is np.sum(arr).dtype == np.float : True>
Koda #2:
Python3
najboljši nasmeh na svetu
# Python Program illustrating> # numpy.sum() method> import> numpy as np> > # 2D array> arr> => [[> 14> ,> 17> ,> 12> ,> 33> ,> 44> ],> > [> 15> ,> 6> ,> 27> ,> 8> ,> 19> ],> > [> 23> ,> 2> ,> 54> ,> 1> ,> 4> ,]]> > print> ('
Sum of arr : ', np.> sum> (arr))> > print> ('> Sum> of arr(uint8) : ', np.> sum> (arr, dtype> => np.uint8))> print> ('> Sum> of arr(float32) : ', np.> sum> (arr, dtype> => np.float32))> > print> ('
Is np.> sum> (arr).dtype> => => np.uint : ',> > np.> sum> (arr).dtype> => => np.uint)> print> ('Is np.> sum> (arr).dtype> => => np.> float> : ',> > np.> sum> (arr).dtype> => => np.> float> )> |
>
java vrednost niza
>
Izhod:
Sum of arr : 279 Sum of arr(uint8) : 23 Sum of arr(float32) : 279.0 Is np.sum(arr).dtype == np.uint : False Is np.sum(arr).dtype == np.float : False>
Koda #3:
Python3
# Python Program illustrating> # numpy.sum() method> > import> numpy as np> > # 2D array> arr> => [[> 14> ,> 17> ,> 12> ,> 33> ,> 44> ],> > [> 15> ,> 6> ,> 27> ,> 8> ,> 19> ],> > [> 23> ,> 2> ,> 54> ,> 1> ,> 4> ,]]> > print> ('
Sum of arr : ', np.> sum> (arr))> print> ('> Sum> of arr(axis> => 0> ) : ', np.> sum> (arr, axis> => 0> ))> print> ('> Sum> of arr(axis> => 1> ) : ', np.> sum> (arr, axis> => 1> ))> print> ('
Sum of arr (keepdimension> is> True> ):
',> > np.> sum> (arr, axis> => 1> , keepdims> => True> ))> |
pete davidson
>
>
Izhod:
Sum of arr : 279 Sum of arr(axis = 0) : [52 25 93 42 67] Sum of arr(axis = 1) : [120 75 84] Sum of arr (keepdimension is True): [[120] [ 75] [ 84]]>