4 ms·
Yeah. Compare A = [1, 2; 3, 4]; x = [5; 6]; y = A * x; with this uglier version: import numpy as np A = np.array([[1, 2], [3, 4]]) x = np.array([[5], [6]
by aborsy 1y ago
Yeah. Compare
A = [1, 2; 3, 4];
x = [5; 6];
y = A * x;
with this uglier version:
import numpy as np
A = np.array([[1, 2], [3, 4]])
x = np.array([[5], [6]])
y = A @ x
- threeducks 1y agoYou don't have to wrap the lists in np.array if you use NumPy functions (or if one of the arguments already is a NumPy array, which usually is the case): from numpy import * A = [[1, 2], [3, 4]] x = [[5], [6]] y = dot(A, x)
- nis251413 1y agoThat's nice, but only works, as I understand it, if you use numpy-only functions, which means that you should not use those who denote also base-pythonic, eg +,* etc operations, because then they are interpreted differently. Eg `A + x` gives [[1, 2], [3, 4], [5], [6]] instead of array([[ 6, 7],[ 9, 10]]) You have to keep track of the context there to know what you can do and what not I guess, which is not ideal.