首页 > 解决方案 > 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

标签: pythonnumpymatplotlib

解决方案


推荐阅读