1

I have a simple text file composed of 8 columns and I read it with loadtxt function. I want to plot as x-axis column6-column7 and as y-axis column7-column8 so I put this command

>>> pl.plot(np.subtract(data2[:,6], data2[:7]), np.subtract(data2[:,7], data2[:,8]))
and it gave this error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: operands could not be broadcast together with shapes (59427) (7,9) 

What is the problem? and how to do that?

1 Answer 1

1

data2[:7] should be data2[:,7] -- you missed a comma. data2[:7] apparently has shape (7,9), while data2[:,6] has shape (50427,). The error message is saying that the two arrays can not be broadcasted to a common shape upon which np.subtract can be applied.

x = data2[:,6] - data2[:,7]
y = data2[:,7] - data2[:,8]
pl.plot(x, y)
Sign up to request clarification or add additional context in comments.

1 Comment

@user2154410 If this solved your problem please accept it (big gray check box on the left)

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.