0

I'm trying to read a file and save to a numpy matrix to display it, but I'm stuck on an error.

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)

And this returns:

Traceback (most recent call last):
  File "[PATH]", line 8, in <module>
    image.data[:] = reader
NotImplementedError: memoryview slice assignments are currently restricted to ndim = 1

Any ideas of what's causing this error?

Edit:

I am using this SO question to write my program: read and display raw image using python

5
  • Did you try image[:], because image.data[:] will return a pointer to the memory. I am assuming you will have to assign the value directly. Commented Nov 5, 2020 at 0:07
  • Why are you trying to assign a value to image.data? Who or what suggested that? The data attribute of an array is a low level object that only the most advanced numpy programmers are allowed to touch :) Commented Nov 5, 2020 at 0:48
  • @AnuragReddy This just returns "Memory Error". Commented Nov 5, 2020 at 2:08
  • @hpaulj See my edit please. Commented Nov 5, 2020 at 2:10
  • @hpaulj Is there a way to assign it directly? Like iterate through the data and assign each index. Commented Nov 5, 2020 at 21:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.