user3408380
user3408380

Reputation: 375

Find negative and positive values in numpy array

I have a numpy array what contains data of m/s wind speed. Both negative and positive values. Now i need to calculate the average number of the wind speed over the negative values and do the same for the positive values. Is this possible ? It's important that the data stays in the array. I had tryed something with numpy.average but without success, as he takes the average of the whole array both positive and negative values.

Thank you!

Upvotes: 4

Views: 17175

Answers (1)

Jakob S.
Jakob S.

Reputation: 1891

The nice thing about numpy is that you can write things like:

 negavg = numpy.mean(windspeed[windspeed < 0.0])
 posavg = numpy.mean(windspeed[windspeed > 0.0])

Upvotes: 9

Related Questions