Get Mode of NumPy Array in Python (2 Examples) | SciPy Library | How to Calculate by Column & Row

Published: 04 July 2022
on channel: Statistics Globe
291
6

How to calculate the mode of a NumPy array in the Python programming language. More details: https://statisticsglobe.com/mode-nump...
Python code of this video:

import numpy as np # Load NumPy library

from scipy import stats

my_array = np.array([[1, 5, 2, 2, 1, 6], # Create example array
[7, 2, 3, 1, 8, 6],
[1, 3, 4, 2, 7, 1],
[1, 3, 2, 2, 8, 5]])
print(my_array) # Print example array
[[1 5 2 2 1 6]
[7 2 3 1 8 6]
[1 3 4 2 7 1]
[1 3 2 2 8 5]]

print(stats.mode(my_array)[0]) # Get mode of array columns
[[1 3 2 2 8 6]]

print(stats.mode(my_array, axis = 1)[0]) # Get mode of array rows
[[1]
[1]
[1]
[2]]

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


Watch video Get Mode of NumPy Array in Python (2 Examples) | SciPy Library | How to Calculate by Column & Row online, duration hours minute second in high quality that is uploaded to the channel Statistics Globe 04 July 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 291 times and liked it 6 visitors.