How to make the individual media of each element in an array

-3

Hello, I have the following array:

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

I need the result with an array of their respective means, like this:

[6.66, 6.66, 6.66]

Thankful

    
asked by anonymous 28.08.2018 / 21:25

1 answer

3

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

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

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

Output from variable media :

[6.66666667 6.66666667 6.66666667]

At documentation you can see better about the parameters.

    
28.08.2018 / 22:01