slimboy
slimboy

Reputation: 1653

How to find the average of an array of tuples with 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?

Upvotes: 2

Views: 2819

Answers (1)

llllllllll
llllllllll

Reputation: 16434

You can use:

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

Or:

a.mean(0)

Upvotes: 8

Related Questions