numpy.sum(arr, akse, dtype, ud): Denne funktion returnerer summen af array-elementer over den angivne akse.
Parametre:
arr: input array.
akse : akse, langs hvilken vi ønsker at beregne sumværdien. Ellers vil den betragte arr som fladtrykt (virker på hele aksen). akse = 0 betyder langs kolonnen og akse = 1 betyder arbejde langs rækken.
ud: Forskelligt array, som vi ønsker at placere resultatet i. Arrayet skal have samme dimensioner som forventet output. Standard er Ingen.
initial: [skalær, valgfri] Startværdien af summen.
Vend tilbage : Summen af matrixelementerne (en skalarværdi, hvis aksen ikke er nogen) eller matrix med sumværdier langs den angivne akse.
Kode #1:
streng til tegn
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>)> |
Neena Gupta
>
>
Produktion:
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>
Kode #2:
Python3
np.histogram
# 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>)> |
>
ubuntu build vigtigt
>
Produktion:
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>
Kode #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>))> |
omdøb i linux bibliotek
>
>
Produktion:
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]]>