How to measure each individual element in a matrix

Asked

Viewed 932 times

-2

Hello, I have the following matrix:

matriz = np.array([
    [5, 5, 5],
    [5, 5, 5],
    [10, 10, 10]
])

and accurate the result with an array of their respective medias, thus:

[6.66, 6.66, 6.66]

Grateful

  • 1

    What you’ve already done? ;)

  • For now just searching the numpy documentation, I would like to resolve this situation with just a numpy function.

  • numpy.average and numpy.meanhelp? Seems to be what you seek

1 answer

4


Using the function numpy.average you can average the values of a array for a given axle. Ex:

matriz = np.array([
    [5, 5, 5],
    [5, 5, 5],
    [10, 10, 10]
])

#media para o eixo Y
media = np.average(matriz, axis=0)

Variable output media:

[6.66666667 6.66666667 6.66666667]

In the documentation you can see better about the parameters.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.