Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
numpy.std() in Python
Next article icon
numpy.mean(arr, axis = None) :Compute the arithmetic mean (average) of the given data (array elements) along the specified axis.
Parameters :arr : [array_like]input array.axis : [int or tuples of int]axis along which we want to calculate the arithmetic mean. Otherwise, it will consider arr to be flattened(works on all the axis). axis = 0 means along the column and axis = 1 means working along the row.out : [ndarray, optional]Different array in which we want to place the result. The array must have the same dimensions as expected output.dtype : [data-type, optional]Type we desire while computing mean.Results : Arithmetic mean of the array (a scalar value if axis is none) or array with mean values along specified axis.
Code #1:Python3 1==
# Python Program illustrating# numpy.mean() methodimportnumpyasnp# 1D arrayarr=[20,2,7,1,34]print("arr : ",arr)print("mean of arr : ",np.mean(arr))
Output :
arr :  [20, 2, 7, 1, 34]mean of arr :  12.8
 Code #2:Python3 1==
# Python Program illustrating# numpy.mean() methodimportnumpyasnp# 2D arrayarr=[[14,17,12,33,44],[15,6,27,8,19],[23,2,54,1,4,]]# mean of the flattened arrayprint("\nmean of arr, axis = None : ",np.mean(arr))# mean along the axis = 0print("\nmean of arr, axis = 0 : ",np.mean(arr,axis=0))# mean along the axis = 1print("\nmean of arr, axis = 1 : ",np.mean(arr,axis=1))out_arr=np.arange(3)print("\nout_arr : ",out_arr)print("mean of arr, axis = 1 : ",np.mean(arr,axis=1,out=out_arr))
Output :
mean of arr, axis = None :  18.6mean of arr, axis = 0 :  [17.33333333  8.33333333 31.         14.         22.33333333]mean of arr, axis = 1 :  [24.  15.  16.8]out_arr :  [0 1 2]mean of arr, axis = 1 :  [24 15 16]

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp