[英]how to set python numpy array size limit
I'm trying to calculate the average size of a contour/ball. 我正在尝试计算轮廓/球的平均大小。 I've used arclength to calculate the perimeter of the ball, then found out the diameter. 我使用弧长计算球的周长,然后找出直径。 My problem is that the contour values is constantly changing. 我的问题是轮廓值不断变化。
I want to input the first 10 values of the diameter into a np.array and calculate the mean to use as my object size. 我想将直径的前10个值输入np.array并计算均值以用作对象大小。 I'm new to python, been trying multiple methods but haven't found a solution to either set the size or extract the first 10 array tuples. 我是python的新手,正在尝试多种方法,但没有找到设置大小或提取前10个数组元组的解决方案。 I've tried pulling u the first 10 using for i in range. 我试过拉你在我范围内使用的前10个。
My current code is: 我当前的代码是:
def average_diam (diameter):
av_diameter = np.array(diameter)
for i in np.arange(1, len(av_diameter)):
for i in av_diameter >= 10:
average = np.mean()
print(average)
perimeter = cv2.arcLength(c, True)
diameter = perimeter / pi
average = average_diam(diameter)
thanks for the help!! 谢谢您的帮助!!
Assuming diameter is an list of elements you simply can do something like 假设直径是元素列表,您可以简单地执行以下操作
def average_diam(x):
av_diameter = np.zeros(10)
for i in range(0, 10):
av_diameter[i] = x[i]
return np.mean(av_diameter)
average_diam(diameter)
You honestly can just do a one liner for this without calling a function: 老实说,您可以为此做一个衬板而无需调用函数:
average = np.mean(np.asarray(diameter[0:10]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.