python - Python-对2D数组中的每个元素执行操作并将其存储在新的2D数组中

标签 python arrays python-3.x numpy opencv

我通过读取灰度图像获得2D阵列。

image = cv2.imread('hurricane katrina 1.jpg', cv2.IMREAD_GRAYSCALE)

我想对2D数组中的每个元素执行操作,并将其存储在另一个2d数组中。所以我做了下面的命令:
R = 255 * abs(math.sin(b * image))

引发错误。
Traceback (most recent call last):
File "C:/Users/alyss/AppData/Local/Programs/Python/Python36/Exercise#4_2.py", line 25, in <module>
R = 255 * abs(math.sin(b * image))
TypeError: only size-1 arrays can be converted to Python scalars

我知道有一种直接的方法可以在Python中完成而不循环。我该怎么办?

最佳答案

I want to perform operations on every element in the 2D array and store it in another 2d array.



使用NumPy库对N-D阵列执行操作。

编辑:
这是一个代码片段。
255 * numpy.absolute(numpy.sin(b * image))

关于python - Python-对2D数组中的每个元素执行操作并将其存储在新的2D数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49766376/

相关文章:

python - 嵌套列表理解

python - 如何在树莓派中更新 python

python - 使用 GroupBy 从长格式到宽格式

c++ - 将数组的所有元素初始化为相同的数字

java - 在java中反转数组并将其分配给新数组

javascript - 更新动态文本框中的现有值时在数组中创建新条目

Python仅枚举反向索引

python - ipython笔记本中的 Pandas 子图标题大小

Python pandas 实现条件类别

python - 在编辑之前使用 python 脚本将 Windows 注册表备份到文件