Calculate the mean of a row or column, and use the dot multiplication on matrices.
Mean and dot
In [1]:
import numpy as np
In [4]:
# create 3 x 1 array
lst = [[6], [7], [8]]
array = np.array(lst)
array
Out[4]:
In [3]:
# create 1 x 3 array
lst_2 = [[2, 2, 2]]
array_2 = np.array(lst_2)
array_2
Out[3]:
In [5]:
# np.mean(array_name)
# it simply sums up all elements and divide the sum by the number of elements
# this will output a single number
np.mean(array)
Out[5]:
In [6]:
# np.mean(array_name)
np.mean(array_2)
Out[6]:
In [9]:
# dot is different from element-wise multiplication
# 3 x 1 dot 1 x 3
# this would output a 3 x 3 array
np.dot(array, array_2)
Out[9]: