首页 > 解决方案 > 我不明白为什么 Python 给我一个 np.darray 对象是不可调用的

问题描述

我想找到离点 p 最近的点,但它不起作用

import numpy as np
import matplotlib.pyplot as plt
point = np.array([[1,1],[1,2],[1,3],[2,1], [2,2],[2,3], [3,1], [3,2], [3,3]])
p = np.array([2.5,2])
plt.plot(point[:,0], point[:,1], "ro")
plt.plot(p[0], p[1], "bo")
**This section is where it got the error**
distance = np.zeros(point.shape[0])
for i in range(len(distance)):
    distance[i] = distance(p, point[i])
distance[4]

标签: pythonnumpy

解决方案


您需要将数组重命名为distance其他名称。目前,distance[i] = distance(p, point[i])Python 尝试调用您的数组而不是distance()函数。


推荐阅读