python - 对数组执行数学函数
问题描述
我是编程新手,所以我可能听起来很幼稚。我有一组数组
matrix([[0.23316744, 0.62686578, 0.23497639, 0.41566779, 0.18428155]]), matrix([[0.26199825, 0.7148431 , 0.2296318 , 0.36555626, 0.18962302]]),............. etc.
我想对每个元素执行 math.arctan 函数并将其恢复为相同的格式以执行进一步的操作。
我不能直接对其执行 math.arctan ,因为它给出了错误
TypeError: must be real number, not list
所以我尝试使用 np.asscalar 来分隔每个术语,但它不起作用并给出错误
TypeError: only size-1 arrays can be converted to Python scalars
在这方面的任何帮助都会非常有帮助。
解决方案
它给了你错误
TypeError: must be real number, not list
因为函数 Math.arctan Expect a number not a List ,一个简单的解决方案是循环到您的列表中,并为每个元素 L[i][j] 执行 L[i][j] = Math.arctan(L[i] [j])
在这段代码中,我想你有一个列表列表,每个子列表都包含数字
for i in range(0,len(l)):
for j in range(0,len(l[i])):
L[i][j] = Math.arctan(L[i][j])
推荐阅读
- angularjs - Spring MVC 与 AngularJS 的完美结合?
- c - 致命错误:omp.h:没有使用 arm-unknown-linux-uclibcgnueabi (crosstool-ng) 的文件或目录
- python - 用于在 python 中传输照片的套接字编程
- visualization - 如何使用从一个图中选择的数据的索引,在另一个图中绘制一些东西?
- debian - 无法在 Debian 9 (Stretch) 上安装 php 7.2
- c++ - 了解 std::isnan 的编译结果
- knockout.js - 从 knockout.js 的下拉菜单中过滤可观察数组
- sql - 返回开始日期和结束日期之间月份的完整列表
- html - 纯 CSS 响应式翻转框
- php - 相等比较在php中不起作用