0

Hi for my code I have to multiply a point/vector (1,0) by matrix [1.00583, -0.087156], [0.087156, 1.00583]. The result should give me a new point (x,y) This is what I have so far:

import matplotlib.pyplot as plt
import numpy as np
A = np.array([[1],[0]])
B = np.array([[1.00583, -0.087156], [0.087156, 1.00583]])
test =np.multiply(A, B)
print (test)

The result still gives me a (2x2) matrix instead of a (2x1) that i can use as a point. Is there another function or a better way of going about this?

alpajay
  • 1
  • 1
  • 1
  • What answer do you expect to get in matrix notation? I ask because usually you see matrix x column_vector, not column_vector x matrix. – Mad Physicist Nov 06 '18 at 03:28

2 Answers2

2

First thing, if you want to do matrix multiplication use numpy.matmul or the @ operator, e.g. B@A.

Also, when you define A like

A = np.array([[1],[0]])

this creates a 2x1 vector (not 1x2). So if you want to multiply the vector A with the matrix B (2x2) this should be C = B*A, where C will be a 2x1 vector

C = B@A

Otherwise if you want to multiply A*B and B is still the 2x2 matrix you should define A as a 1x2 vector:

A = np.array([1,0])

and get a 1x2 result with

C = A@B
b-fg
  • 3,372
  • 2
  • 22
  • 39
0
test =np.matmul(B,A)

This should do the trick.

achyuta26
  • 3
  • 3