python - a.any() 或 a.all() 了解如何解决此问题
问题描述
我对这个错误没有任何想法,
import NumPy as np
X = np.array([[1,2,3],
[4,5,100],
[-1,2,100],
[3,8,9232020]])
print(X)
print('\n Dimension of the array is:')
print(X.shape)
def getMax(X):
this_max=X[0]
for e in X:
if e > this_max:
this_max=e
return this_max
x_max=getMax(X)
print('x_max',x_max)
print('x_max', np.max(X))
错误是“如果 e > this_max:”,它告诉我具有多个元素的数组的真值是不明确的。使用 a.any() 或 a.all(),我不知道如何修复它。
解决方案
每个 e 代表 X 中的一个列表,例如 X[0] = [1,2,3]。我假设您想遍历数组中的每个列表以找到数组中所有列表的最大值。
推荐阅读
- python - 使用 NLTK 或 PATTERN 重复标签磁盘“C://C://..spark-core_2.11-2.3.2.jar”之类的导入惰性时,PYTHONPATH 错误 [Windows 123] 与 Pyspark
- python - 在jupyter中通过python进行网络爬行时无法获取整个html表格内容
- visual-studio-code - vscode 从“更改所有匹配项”中取消选择一项
- java - 如何为不同的环境运行 JUnit 5 测试套件 [micronaut 1.2.5]?
- android - 未处理的错误。('平台“android”似乎不是一个有效的cordova平台。它缺少API.js。不支持android。')
- linux - 循环过滤掉apache日志文件中的行
- angular - 发现很难将控制台上显示的数据显示在视图中
- string - 有没有办法在powershell中转义变量调用?
- apache - 无法访问 Spotfire 服务器 - 没有 Web 界面(仅 SSH 有效)
- html - 在 CSS 中发出样式,以便每个奇数 div 更改颜色和位置