Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the average of an array of tuples with numpy

Tags:

python

numpy

I have an array that looks like this:

sample_array = [(1,3),(2,2),(3,1)]

I need to find the average to output :

>> [2,2]

I tried the code below

np.average(left_lane)

but it returns

>> 2.0

How can I make it so that it returns two values without having to loop?

like image 434
slimboy Avatar asked Jan 24 '26 14:01

slimboy


1 Answers

You can use:

a = np.array(sample_array)
np.average(a, axis=0)

Or:

a.mean(0)
like image 55
llllllllll Avatar answered Jan 27 '26 04:01

llllllllll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!