how to multiply a matrix with a column vector in python
- User
how to multiply a matrix with a column vector in python
Assistant
To multiply a matrix with a column vector in Python, you can use the
numpy.dot()function. This function takes two arguments: the matrix and the column vector, and returns the product of the two.For example, the following code multiplies a 3x3 matrix with a 3x1 column vector:
import numpy as np matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) column_vector = np.array([[1], [2], [3]]) product = np.dot(matrix, column_vector) print(product)This code will output the following result:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.