python - Python/Numpy — NotImplementedError:memoryview 切片分配当前限制为 ndim = 1
问题描述
我正在尝试读取一个文件并保存到一个 numpy 矩阵以显示它,但我遇到了一个错误。
from matplotlib import pyplot as plt
import numpy as np
image = np.empty((1664, 512, 256), np.uint16)
reader = open('Datasets/burned_wood_with_tape_1664x512x256_12bit.raw', "rb").read()
image.data[:] = reader
plt.imshow(image)
这会返回:
Traceback (most recent call last):
File "[PATH]", line 8, in <module>
image.data[:] = reader
NotImplementedError: memoryview slice assignments are currently restricted to ndim = 1
关于导致此错误的任何想法?
编辑:
我正在使用这个 SO 问题来编写我的程序:read and display raw image using python
解决方案
推荐阅读
- android - 是否可以使用 Android Jetpack 创建具有不同参数的多个加密密钥?
- python - 从数组存储积分值,然后使用该新数组
- selenium - 使用 selenium ,我试图在兄弟姐妹中使用 x 路径从一个元素移动到另一个元素
- python - 在不同脚本中使用库中不同版本的函数的最佳方法是什么?
- javascript - 我不理解使用 redux.js 和 redux-toolkit 的 reactjs 中的以下代码,问题是如何使用 useEffeec() 更新状态?
- python - 遍历 Python 中的两个键
- powershell - 嵌套的 Powershell 对象取消引用
- javascript - 如果有人选中复选框 html,则添加分数
- php - 如何从 php 联系表中删除 get 500 错误?
- javascript - 如何在传单地图中添加图例