精度
让我们来看一个示例,其中我们可以为输出指定数据类型。
import numpy as np
inp = [22, 2, 17, 11, 34]
print("The input array is : ")
print(inp)
## 计算标准差
print("The standard deviation of the Input Array is: ")
print(np.std(inp))
## 使用 float32 获得更高精度
print("\nTo get More precision with float32")
print("Thus std of array is : ", np.std(inp, dtype=np.float32))
## 使用 float64 获得更高准确性
print("\nTo get More accuracy with float64")
print("The std of array is : ", np.std(inp, dtype=np.float64))
输出:
The input array is:
[22, 2, 17, 11, 34]
The standard deviation of the Input Array is:
10.721940122944167
To get More precision with float32
Thus std of array is : 10.72194
To get More accuracy with float64
The std of array is: 10.721940122944167
注意:为了更准确地计算标准差,使用了 dtype float64
。