- type() / dtype() / astype()的区别
type() 返回参数的类型,比如“list,numpyndarray,tensor”
dtype() 返回数组中元素的类型,比如“int64,float64,complex64”
astype() 转换数据类型,比如“a = a.astype(int)将a数组内的元素转换为int类型”
2. python 异常输出美化工具
import pretty_errors
3. pytorch中的文件导入方式
- 文件目录
--|
- 场景1 main.py 要导入fileA.py中的fun1函数
方式1:不用__init__.py文件,在main.py中写
from .packageA.fileA import fun1
方式2: 修改__init__.py文件,写入
from .fileA import fun1
在main.py中写
from .packageA import fun1
类似通过__init__.py文件实现跨目录调用
- 场景2 fileB.py 要导入fileA.py中的fun1函数
在fileB.py中写
from ..packageA.fileA import fun1