Decimal separation of an item does not work properly

The docs show how element separation works

a1 = np.array([8,12,14])
b1 = np.array([4,6,7])
a1/b1
array([2, 2, 2])

What works. I am trying to use the same thing on different arrays, and it is not. For two 3-dimensional vectors, a 3 × 3 matrix is ​​returned. I even made sure that their “shape is the same”, but not a difference.

>> t
array([[  3.17021277e+00],
       [  4.45795858e-15],
       [  7.52842809e-01]])
>> s
array([  1.00000000e+00,   7.86202619e+02,   7.52842809e-01])
>> t/s
array([[  3.17021277e+00,   4.03231011e-03,   4.21098897e+00],
       [  4.45795858e-15,   5.67024132e-18,   5.92149984e-15],
       [  7.52842809e-01,   9.57568432e-04,   1.00000000e+00]])
t/s.T
array([[  3.17021277e+00,   4.03231011e-03,   4.21098897e+00],
       [  4.45795858e-15,   5.67024132e-18,   5.92149984e-15],
       [  7.52842809e-01,   9.57568432e-04,   1.00000000e+00]])
+4
source share
1 answer

, t.shape = (3,1) s.shape = (3,). , : , , -, , , , , : .

,

t[:,0] / s

np.squeeze(t) / s

t. , ! , , , :

a = np.arange(3)
b = np.arange(3)

:

a*b = [0,1,4]

, , :

a[np.newaxis,:] * n[:,np.newaxis]

! , , .

+7

Source: https://habr.com/ru/post/1547235/


All Articles