To find the average of all elements in an array, you can use the numpy library in python. The numpy.mean() function can be used to calculate the average of all elements in an array. Here's an example code snippet:
main.py83 chars7 lines
This will output:
main.py4 chars2 lines
In this example, we import the numpy library and create an array arr
with five elements. We then use the np.mean()
function to calculate the average of all elements in the array arr
. Finally, we print the result which is 3.0.
gistlibby LogSnag