0
img = mpimg.imread('file.tif') #imports image

im_x = np.sum(img, axis=0) #sum the rows of the array

hist = pl.hist(im_x) #returns a list - this works fine

test = np.array(hist) #turns hist into a numpy array so i can plot it

plt.plot(test)
plt.show()

I'm trying to import an image to an array, sum the values of each row, then plot this in a histogram.

The code above gives me the 'setting an array element with a sequence error' message, which I don't understand as it's a numpy array.

I've only been using python for a week, so it could be something really obvious I'm doing wrong.

1 Answer 1

1

In the words of Henry David Thoreau, simplify, simplify:

img = mpimg.imread('file.tif') #imports image    
im_x = np.sum(img, axis=0) #sum the rows of the array
plt.hist(im_x)
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

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.