Is there any pythonic way to find average of specific tuple elements in array?

前端 未结 8 1286
你的背包
你的背包 2021-01-01 11:35

I want to write this code as pythonic. My real array much bigger than this example.

( 5+10+20+3+2 ) / 5

print(np.mean(array,key=lambda x:x[1])

8条回答
  •  没有蜡笔的小新
    2021-01-01 12:02

    If you're open to more golf-like solutions, you can transpose your array with vanilla python, get a list of just the numbers, and calculate the mean with

    sum(zip(*array)[1])/len(array)
    

提交回复
热议问题