1

I am new to python,
I have a binary image file (unsigned 16-bit format and 512x512 pixel in size),but while using a python code I am getting error "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"

I am running the code as shown

import numpy as nmp
from matplotlib import pylab as pt

I = nmp.fromfile('raw.dat', dtype='int16', sep="")
I = I.reshape([512, 512])

pt.imshow(I)
pt.show(I)

can anybody please tell me where I am doing wrong?

2
  • You should post your full traceback. Also the sep keyword isn't necessary for numpy.fromfile here... Commented Jan 30, 2014 at 20:02
  • 1
    Oh, I see your problem. Commented Jan 30, 2014 at 20:02

1 Answer 1

2

pylab.show() does not take an array as an argument. It just shows what you've already plotted with imshow.

Sign up to request clarification or add additional context in comments.

2 Comments

but using pylab.imshow(), i am getting this msg "<matplotlib.image.AxesImage at 0x8a97fd0>"
That's normal. It returns a reference to the image axes. It's just telling you that imshow returns an AxesImage object. You can assign this to a variable like axes = plt.imshow(arr) and make changes to to how the image is formatted before displaying it with show(). But that's more advanced and not something you need to worry about right now. Try going through some examples in the Matplotlib gallery like matplotlib.org/examples/images_contours_and_fields/…

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.