TypeError:|TypeError: only size-1 arrays can be converted to Python scalars解决办法
def ori_point(points):
if len(points) == 1:
origin = points[0]
else:
xyzmean = np.mean(np.array(points), axis=0)
distances = np.sqrt(np.sum(np.asarray(xyzmean - points) ** 2, axis=1))
origin = points[int(np.where(distances == np.min(distances))[0])]
return origin
【TypeError:|TypeError: only size-1 arrays can be converted to Python scalars解决办法】选择所有点中距离xyzmean最近的点,由于有多个点与xzymean的距离相同,导致无法正确选择距离最近,导致np.where(distances == np.min(distances)的返回值是具有多个索引值得元祖,故报错
文章图片
改正方法改为:int(np.where(distances == np.min(distances))[0][0])永远取元祖中的第一个数字
推荐阅读
- 由Uncaught|由Uncaught TypeError: this.player.startMoveAt is not a function引申
- Python|Python TypeError: 'module' object is not callable 原因分析
- 11月18日:I|11月18日:I choose only peace
- AnnotationTransactionAttributeSource is only available on Java 1.5 and higher
- ART 的 interpret-only模式源码及调用流程 & QuickCompiler后端调用流程
- Type|Type annotations can only be used in TypeScript files.ts(8010)
- Python3|Python3 TypeError: only size-1 arrays can be converted to Python scalars
- TypeError: Object of type ‘datetime‘ is not JSON serializable
- robot framework 报错TypeError: not unicode的解决办法直接修改为click element
- TypeError:|TypeError: an integer is required (got type str)