Home > other >  Use NumPy inconsistent results matrix operations
Use NumPy inconsistent results matrix operations

Time:10-02

Two matrix, the dot product directly draw a line after operation, and drew a line from the first matrix and then to the dot product operation result,

Code:
X=np. Random. Randn (50, 1000)
Y=X [0]
W=np. Random. Randn (1000, 10)
A=X.d ot (W)
B=Y.d ot (W)

Test:
B==A [0]
Results:
Array ([True, False, False, False, False, False, False, False, False, False])

Test:
Y.d ot (W) - X.d ot (W) [0]
Results:
E+00 array ([0.00000000, 6.66133815 e-15, e-14, 2.22044605 1.06581410 e-14,
E-14 e-15, 8.88178420-2.30926389, 2.84217094 e-14, 3.28626015 e-14,
4.48530102 e-14, 3.90798505 e-14])

The result is correct? If you can get the same results?

Environment: Windows 10, Python3.7 NumPy1.17.4

Thank you,

CodePudding user response:

Brother, I had a test, your results not ah, I use your code the result is that environment and you:
[True True True True True True True True True True]
[0. 0 0. 0. 0, 0, 0, 0, 0, 0.]
Code:
 #! The/usr/bin/env python 
# - * - coding: utf-8 - * -
The import numpy as np

X=np. Random. Randn (5, 10)
Print (" -- -- -- -- -- - "X, X)
Y=X [0]
Print (" -- -- -- -- -- - "Y, Y)
W=np. Random. Randn (10, 10)
Print (" W -- -- -- -- -- - ", W)
A=X.d ot (W)
B=Y.d ot (W)

# print (" A ", A)
# print (" B ", B)

# test:
Print (B==A [0])
# results:
# array ([True, False, False, False, False, False, False, False, False, False])

Print (" -- "* 20)
# test:
Print (Y.d ot (W) - X.d ot (W) [0])
# results:
# array ([e-15 e+00 0.00000000, 6.66133815, 2.22044605 e-14, 1.06581410 e-14,
E-14 e-15 # 8.88178420, 2.30926389, 2.84217094 e-14, 3.28626015 e-14,
# 4.48530102 e-14, 3.90798505 e-14])

# the results is correct? If you can get the same results?
  • Related