๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.4 โ€บ reference โ€บ generated โ€บ numpy.mean.html
numpy.mean โ€” NumPy v2.4 Manual
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. By default, float16 results are computed using float32 intermediates for extra precision. ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> np.mean(a) 2.5 >>> np.mean(a, axis=0) array([2., 3.]) >>> np.mean(a, axis=1) array([1.5, 3.5])
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.1 โ€บ reference โ€บ generated โ€บ numpy.mean.html
numpy.mean โ€” NumPy v2.1 Manual
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. By default, float16 results are computed using float32 intermediates for extra precision. ... >>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> np.mean(a) 2.5 >>> np.mean(a, axis=0) array([2., 3.]) >>> np.mean(a, axis=1) array([1.5, 3.5])
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-mean-in-python
numpy.mean() in Python - GeeksforGeeks
June 26, 2026 - numpy.mean() is used to calculate the arithmetic mean (average) of numeric data.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ starting to use numpy and was curious about getting the mean for each row and each column? i don't really understand the axis's fully.
r/learnpython on Reddit: Starting to use numpy and was curious about getting the mean for each row and each column? I don't really understand the axis's fully.
June 13, 2022 -

I have only implemented it into my additon section so far. But I am trying to print the mean of each row and each column? If that is possible but I am still wrapping my head around the axis's. Any tips or advice would be awesome.

 numpy_list = []
    length_list = 9
    print("Please enter 9 numbers multiples of 2.")
    for i in range(length_list):
        numpy_list.append(float(input("Enter that number!\n")))
    numpy_list = np.array(numpy_list)
    print(np.floor(numpy_list))
    print("\n")

    numpy_list2 = []
    length_list2 = 9
    print("Please enter 9 more numbers for a second matrix. Remember multiples of 2!\n")
    for j in range(length_list2):
        numpy_list2.append(float(input("Enter that number NOWWW!\n")))
    numpy_list2 = np.array(numpy_list2)
    print(np.floor(numpy_list2))
    print("\n")

    print(numpy_list.reshape(3, 3))
    print("\n")
    print(numpy_list2.reshape(3, 3))
    print("\n")

    selection = 0
    while selection != 5:

        selection = int(input("What would you like to do to the matrices?\n"
                      "1: Add\n"
                      "2: Subtract\n"
                      "3: Multiply\n"
                      "4: Element to element multiplication\n"
                      "5: To exit.\n"))

        if selection == 1:
            added = numpy_list + numpy_list2
            print(added.reshape(3, 3))
            print("This is the transpose: \n", np.transpose(added).reshape(3, 3))
            added_col_ave = np.mean(added, axis=0)
            print("The average of the columns is:", added_col_ave)
            added_row_ave = np.mean(added, axis=0)
            print("The average of the rows is:", added_row_ave)

This is what I am currently working with.

Top answer
1 of 2
2
Check out the NumPy documentation on the mean method . You'll see in the example given that axis=None returns the mean of every element in the array. axis=0 returns the mean of each column as an array. axis=1 returns the mean of each row as an array. You can confirm this by creating a non-square matrix, say 3x4 (3 rows by 4 columns). When you take np.mean of that matrix with axis=0, you'll get a 1-dimentional array with 4 elements. When you take np.mean with axis=1, you'll get a 1-dimensional array with 3 elements. With a small matrix like this, you can also hand-compute the means and confirm that NumPy is giving you the column or row means depending on your choice of axis. If you're not already doing so, I strongly recommend using Jupyter notebooks to quickly test small snippets of code. If you're not sure how something like np.mean works, you can throw a test into a notebook and get instant feedback on your test. That's how I did the test I described in the second paragraph. (FWIW, the plural of "axis" is "axes". I'm normally not this pedantic on reddit, but I'm learning that clear communication when talking about code goes a long way to minimizing confusion, so I feel like it's worth pointing out here.)
2 of 2
2
OP I strongly suggest you start using Jupyter notebooks. You will be able to see the output instantly and isolate variables and chunks of code in cells. Learning like this with multiple input prompts inside of a for loop is wasting time, because need to write out all the code for the inputs and all. Time that could have been spent learning the actual thing you are trying to learn. Anyways. Heres how it works. Let's make a 3x3 array. np.arange(9).reshape((3,3)) Output = array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) Lets get the means down the rows. Its obvious that ir should be 1,4,7. np.arange(9).reshape((3,3)).mean(axis = 1) Output = array([1., 4., 7.]) Now the means through the columns. Obvious it should be 3,4,5. np.arange(9).reshape((3,3)).mean(axis = 0) Output = array([3., 4., 5.]) Also OP just know that numpy is used for vectorization, if you are using loops in numpy especially when you are starting off, you are doing it wrong! Watch this talk by Jake Vanderplas , its an excellent tutorial on the basics on NumPy and how you can just eschew loops altogether. He even implements KNN without a single loop at the end of the video.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.5 โ€บ reference โ€บ generated โ€บ numpy.mean.html
numpy.mean โ€” NumPy v2.5 Manual
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. By default, float16 results are computed using float32 intermediates for extra precision. ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> np.mean(a) 2.5 >>> np.mean(a, axis=0) array([2., 3.]) >>> np.mean(a, axis=1) array([1.5, 3.5])
Find elsewhere
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.average.html
numpy.average โ€” NumPy v2.6.dev0 Manual
>>> import numpy as np >>> data = np.arange(1, 5) >>> data array([1, 2, 3, 4]) >>> np.average(data) 2.5 >>> np.average(np.arange(1, 11), weights=np.arange(10, 0, -1)) 4.0
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ numpy โ€บ mean
NumPy mean()
The `mean()` function is typically used to compute the average of an entire array or along a specific axis, helping to summarize large datasets with a single representative number. It is especially useful in statistical analysis and data preprocessing. numpy.mean(a, axis=None, dtype=None, out=None, ...
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ numpy
NumPy: Sum, mean, max, min for entire array, column/row-wise | note.nkmk.me
January 20, 2024 - NumPy allows you to calculate the sum, average, maximum, and minimum of an array (ndarray) using functions such as np.sum(), np.mean(), np.max(), and np.min(). These functions allow you to specify the axis argument to obtain results for each ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.3 โ€บ reference โ€บ generated โ€บ numpy.mean.html
numpy.mean โ€” NumPy v2.3 Manual
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. By default, float16 results are computed using float32 intermediates for extra precision. ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> np.mean(a) 2.5 >>> np.mean(a, axis=0) array([2., 3.]) >>> np.mean(a, axis=1) array([1.5, 3.5])
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python:numpy โ€บ built-in functions โ€บ .mean()
Python:NumPy | Built-in Functions | .mean() | Codecademy
June 13, 2025 - The .mean() method calculates and returns the arithmetic mean of elements in a NumPy array. It computes the average by summing all elements along the specified axis and dividing by the number of elements.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ methods โ€บ mean
NumPy mean()
The mean() method computes the arithmetic mean of a given set of numbers along the specified axis. The mean() method computes the arithmetic mean of a given set of numbers along the specified axis. import numpy as np # create an array array1 = np.array([0, 1, 2, 3, 4, 5, 6, 7]) # calculate ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.1 โ€บ reference โ€บ generated โ€บ numpy.nanmean.html
numpy.nanmean โ€” NumPy v2.1 Manual
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32. Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. ... >>> import numpy as np >>> a = np.array([[1, np.nan], [3, 4]]) >>> np.nanmean(a) 2.6666666666666665 >>> np.nanmean(a, axis=0) array([2., 4.]) >>> np.nanmean(a, axis=1) array([1., 3.5]) # may vary
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.mean.html
numpy.mean โ€” NumPy v2.6.dev0 Manual
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. By default, float16 results are computed using float32 intermediates for extra precision. ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> np.mean(a) 2.5 >>> np.mean(a, axis=0) array([2., 3.]) >>> np.mean(a, axis=1) array([1.5, 3.5])
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.mean.html
numpy.mean โ€” NumPy v2.2 Manual
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. By default, float16 results are computed using float32 intermediates for extra precision. ... >>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> np.mean(a) 2.5 >>> np.mean(a, axis=0) array([2., 3.]) >>> np.mean(a, axis=1) array([1.5, 3.5])
๐ŸŒ
Interactive Chaos
interactivechaos.com โ€บ en โ€บ python โ€บ function โ€บ numpymean
numpy.mean | Interactive Chaos
January 21, 2019 - The numpy.mean function returns the average of the elements in array a. By default the average of the array is calculated once it is flattened.
๐ŸŒ
Data Science Dojo
discuss.datasciencedojo.com โ€บ python
How to find the mean of a Numpy array? - Python - Data Science Dojo Discussions
November 22, 2022 - The numpy.mean() function computes the average of all the values in a numpy array. It returns a single value that represents the arithmetic mean of the input array. Example We can also calculate the mean across different axes such as rows or ...