NUMPY notes




Reading a 3x3 array in a single line:

import numpy as np
np.set_printoptions (precision=4, linewidth = 200);

ar = np.array([input().strip().split()], int)
ar = np.resize (ar, (3,3))
print (ar)


Creating random arrays

import numpy as np
np.set_printoptions (precision=4, linewidth = 200);

a = np.random.random ((5,5))
b = np.random.random ((5,5))
c = np.random.random ((144))
c = np.resize (c, (12, 12))
print ("12x12 random [0, 1)\n" + str(c))

c = np.random.randint (100, 1000, 144)
c = np.resize (c, (12, 12))
print ("\n12x12 random integers [100, 1000)\n" + str(c)

Math operations - a, b, and c are numpy arrays
of course, a and b must be conformable.
c = a + b # regular element by element addition
c = a - b # regular element by element subtraction
c = a * b # this is element by element multiplication
c = a @ b # this is regular matrix multiplication.
c = np.matmul (a, b) # same as line above.












(end)