简体   繁体   中英

What is 1. in Math or numpy? Is it supposed to mean 1.0?


A = np.array([[1, -2, 1], [2, 1, -3], [1, -3, 3]])
b = np.array([6, -3, 10])
x = np.linalg.solve(A, b)
print(x) 
#[ 1. -2.  1.]

What format is this? This is my first time seeing it. how does it translate to normal numbers?

The number 1. is a shorter way of writing 1.0 , and indicates that we are not dealing with an integer, but rather a floating point number. Consider following outputs:

>>> import numpy as np
>>> print(np.array([1,-2,1], dtype=float)) 
[ 1. -2.  1.]
>>> print(np.array([1,-2,1], dtype=int))
[ 1 -2  1]
>>> print(np.array([1,-2,1], dtype=np.float32))
[ 1. -2.  1.]
>>> print(np.array([1,-2,1], dtype=np.float16))
[ 1. -2.  1.] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM