0

I have 2 numpy array with equal shape.

V = [[-1 -1 -1] [-2 -2 -2] [-3 -3 -3]]
U = [[1 2 3] [2 3 4] [3 4 5]]

I want to convert matlab to python for below line.

Ot = U*([V(:,1) V(:,2) -V(:,3)])';

I want to convert this matlab code in python.
How can I do that? Inside V(:,1) and V(:,2) are multiplying?

2

1 Answer 1

1

It's not multiplying V(:,1) by V(:,2), it's just separating them by white space. code [V(:,1) V(:,2) -V(:,3)] in matlab just generates matrix:

>> [V(:,1) V(:,2) -V(:,3)]

ans =

    -1    -1     1
    -2    -2     2
    -3    -3     3

so the equivalent could be:

In [90]: V = np.array([[-1, -1, -1], [-2, -2, -2], [-3, -3, -3]])
    ...: U = np.array([[1, 2, 3], [2, 3, 4], [3, 4, 5]])

In [91]: V[:, 2]*=-1

In [92]: Ot = U.dot(V.T)

In [93]: Ot
Out[93]: 
array([[ 0,  0,  0],
       [-1, -2, -3],
       [-2, -4, -6]])
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.