0

I have two matrices - D,c - 100x2 and 100x1 respectively. c consists of 1,-1 only. In MATLAB, I have scatter(D(c==1,1),D(c==1,2),'r');

When I try plt.scatter(D(c==1,1),D(c==1,2),c='r') for Python (imports not shown), it gives an error - 'numpy.ndarray' object is not callable.

How do I access the c indices in Python?

1
  • You should rather describe, what your desired output is. If you hope for somebody, who knows the Matlab behaviour, then you restrict the number of people that may be able to help you. Commented Jun 19, 2018 at 23:30

1 Answer 1

1

Correct if I'm wrong, but if I remember correctly, in MATLAB, writing D(c==1,1) is equivalent of saying:

"All rows for the first column of the array 'D', where the array 'c' has value 1 on the same row".

So, essentially, you want to filter D by using c.

Translating into Python, it looks very similar:

plt.scatter(D[0][c==1],D[1][c==1],color='r')

Just a reminder that in Python, indices start from 0, and slicing/indexing lists is done with square brackets (some_list[some_index)]), not with parenthesis (some_list(some_index)`).

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

4 Comments

You're right about the MATLAB part but executing your Python command throws up error. I'm debugging it right now.
Maybe it is because I considered D and c as 2x100 and 1x100 instead of 100x2 and 100x1, which is the usual way of working with data on Python. Obviously, you're free to change it up to fit your needs
Interestingly, I transposed D and c into 2x100 and 1x100 and then executed your command. It still gives this error Traceback (most recent call last): File "<ipython-input-190-5bda6513bfee>", line 1, in <module> plt.scatter(D[0][c==1],D[1][c==1]) IndexError: too many indices for array
Are you sure D is a two dimensional array? IndexError: too many indices for array probably means your array is either 1-D or it is None.

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.