简体   繁体   English

构建一个 function,它采用二维数组并在 python 中打印平均值

[英]building a function that takes 2d array and prints average in python

I need a way to build a function that takes a 2d array and prints the average, using numpy.我需要一种方法来构建一个 function,它采用二维数组并使用 numpy 打印平均值。

how do I do that?我怎么做?

thanks!谢谢!

Is it a numpy array?它是 numpy 阵列吗? If so, you could just use如果是这样,你可以只使用

arr.mean()

if it is just a nested list, you could turn in into numpy array first如果它只是一个嵌套列表,你可以先变成 numpy 数组

np_arr = np.array(arr)
np_arr.mean()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM