python - 我不明白为什么 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]
解决方案
您需要将数组重命名为distance
其他名称。目前,distance[i] = distance(p, point[i])
Python 尝试调用您的数组而不是distance()
函数。
推荐阅读
- android - Hive 错误 - 使用 0 个类型参数声明类型“TypeAdapter”,但给出了 1 个类型参数
- swift - 如何在 Xcode 13 iOS 15 中为 UINavigationBar 制作分离的阴影外观
- java - Jenkinsfile 参数问题:使用多个参数运行 bat maven 时出现问题
- excel - 获取多区域联合的外部边界范围
- python - 来自 ODB 的最大压力
- python - 将字典写入 csv 时偶尔出现 PermissionError
- msal - 有什么方法可以在 MSAL 中处理 AADSTS50105?
- python-3.x - PyQt6:AttributeError:类型对象'QImage'没有属性'Format_RGB888'
- visual-studio - 如何在 Visual Studio 中处理 csharp 自动化中的弹出窗口
- reactjs - 为什么应该避免使用 refs 的命令式代码?(使用ImperativeHandle)