在深度学习的实现过程中,经常会出现数组和矩阵的计算
NumPy的数组类提供了很多边界的方法, 在实现深度学习的过程中是非常方便的
NumPy是外部类
指的是不包含在标准版的python中,首先需要导入NumPy库
# 来试一下年轻人的第一个NumPy库
import numpy as np # 导入的时候顺便给他起个别名
# 来试一下年轻人的第一个NumPy库
import numpy as np
x = np.array([1.2, 2.0, 3.0])
print(x)
print(type(x))
D:\ANACONDA\envs\pytorch\python.exe C:/Users/Administrator/Desktop/Code/learn_pytorch/first_demo.py
[1.2 2. 3. ]
<class 'numpy.ndarray'>
Process finished with exit code 0
注意:在写代码的过程中
方法的参数含义可能会记不清
- 按一下Ctrl+P来进行查看
- 有默认值的就不管了
- 没有默认值的就自己写
终极大法:看程序源码!
size运算的实现
# 来试一下年轻人的第一个NumPy库
import numpy as np
x = np.array([1.0, 2.0, 3.0])
# print(x)
# print(type(x))
y = np.array([2, 4, 6])
# 加法运算
print(x + y)
# 减法运算
print(x - y)
# 乘法运算
print(x * y)
# 除法运算
print(x / y)
D:\ANACONDA\envs\pytorch\python.exe C:/Users/Administrator/Desktop/Code/learn_pytorch/first_demo.py
[3. 6. 9.]
[-1. -2. -3.]
[ 2. 8. 18.]
[0.5 0.5 0.5]
Process finished with exit code 0
print(2*x)
也是可以实现的
element-wise 对应元素的