0.设备问题
有时在计算的过程中在不同的设备之间来回赋值,可能导致误差(e-05与e-01的差距)。
1. 创建变量时,指名dtype ,如整数可选int64
int64 意思是64位整数(64bit interger), 相当于 long long 占8个字节 -9223372036854775808 ~ 9223372036854775807
a = ([6, 9], dtype=np.int64)
2. Decimal fixed point and floating point arithmetic
3. @专注于矩阵乘法de中缀算子A dedicated infix operator for matrix multiplication
.manual_seed生成随机数种子
在神经网络中,参数默认是进行随机初始化的。如果不设置的话每次训练时的初始化都是随机的,导致结果不确定。如果设置初始化,则每次初始化都是固定的。
设置随机种子是为了确保每次生成固定的随机数,这就使得每次实验结果显示一致了,有利于实验的比较和改进。
()和(),根据给定的两个值,绝对公差或相对公差来判断确定是否被认为是接近的
6. ()
在网络构建完成之后使用()可将将所有的浮点类型的参数和缓冲转换为(双浮点)double数据类型.
()
7.相关链接
Function Signature Object
The one million limit
Data Classes
Minor API improvements for binary sequences
General purpose decorator clause (aka “@in” clause)
Adding a Rational Type to Python
Adding a Rational Literal to Python
Unifying Long Integers and Integers统一长整数和整数
重新设计 Python 的数值模型
日志模块
警告模块
numpy:@矩阵乘法,*矩阵point-wise乘
torch:@矩阵乘法,*矩阵point-wise乘
两个浮点变量相乘结果为什么不精确
浮点数为什么不精确?
为什么浮点数标准无法精确表示0.1?
参考1
[numpy] array和ndarray的区别:array是创建ndarray类型数据的方法。
实际项目相关的做法:
在一些项目交互中,前后端交互数据也可能出现问题,雪花算法ID,对应的后端Long类型,前端number类型,它们的精度不一样,导致精度丢失;解决:转成字符串返给前端
文本数据高精度打印
from decimal import *
import numpy as np
from matplotlib import pyplot as plt
def openreadtxt(file_name):
loss1 = []
loss2 = []
loss3 = []
file = open(file_name, 'r') # 打开文件
file_data = () # 读取所有行
for row in file_data:
find1 = "Loss"
if find1 in row:
# (row) # 将每行数据插入data中
( Decimal( row[17:25]) )
(Decimal(row[39:47])) # 使用 float(row[39:47])会有舍入误差
(Decimal(row[62:70]))# 防止舍入误差
return loss1,loss2,loss3
if __name__ == "__main__":
loss1,loss2,loss3 = openreadtxt('')
print(loss1)
print(loss2)
print(loss3)
# 绘图
x = (0, len(loss2), len(loss2))
(x, loss2, label="loss2", linewidth=1.5)
(x, loss3, label="loss3", linewidth=1.5)
("epoch")
("loss")
()
()