![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Numpy
饿了就干饭
经常更新NLP、深度学习相关内容,感兴趣的话可以关注哈~
展开
-
Numpy-浅拷贝和深拷贝
import numpy as nparr1 = np.array([1,2,3])#浅拷贝arr2 = arr1#arr1和arr2共享一块内存arr2[0] = 5print(arr2)[5 2 3]print(arr1)[5 2 3]#深拷贝arr3 = arr1.copy()arr3[0] = 10print(arr3)[10 2 3]print(arr1)[5 2 3]原创 2021-12-21 09:40:24 · 64 阅读 · 0 评论 -
Numpy-矩阵的分割
import numpy as np arr1 = np.arange(12).reshape((3,4))print(arr1)[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]]#水平方向分割,分成2份arr2,arr3 = np.split(arr1,2,axis = 1)print(arr2)[[0 1] [4 5] [8 9]]print(arr3)[[ 2 3] [ 6 7] [10 11]] #垂直方向分割,分成3份a原创 2021-12-20 20:59:26 · 1334 阅读 · 0 评论 -
Numpy-矩阵的合并
import numpy as nparr1 = np.array([1,2,3])arr2 = np.array([4,5,6])#矩阵的垂直合并arr3 = np.vstack((arr1,arr2))print(arr3)[[1 2 3] [4 5 6]]#矩阵的水平合并arr4 = np.hstack((arr1,arr2))print(arr4)[1 2 3 4 5 6]#3个矩阵的垂直合并arrv = np.vstack((arr1,arr2,arr3))pr原创 2021-12-20 20:56:30 · 2977 阅读 · 0 评论 -
Numpy-查看数组的属性
import numpy as np#定义一个矩阵array = np.array([[1,2,3],[4,5,6],[7,8,9]])print(array)[[1 2 3] [4 5 6] [7 8 9]] #查看矩阵的维度 矩阵有几个方括号就是几维的矩阵print(array.ndim)3#查看矩阵的形状print(array.shape)(3,3)即三行三列#查看矩阵的大小,输出矩阵中有多少个数print(array.size)9#查看矩阵中元素的属性,原创 2021-12-20 20:46:55 · 748 阅读 · 0 评论 -
Numpy-随机生成以及矩阵的运算
import numpy as np#生成三行两列的从0到1的元素是随机数的矩阵simple1 = np.random.random((3,2))print(simple1)[[0.02619904 0.49869176] [0.00253581 0.32766397] [0.28004011 0.44864681]]#numpy.random.normal(loc=0,scale=1e-2,size=shape)#其参数意义为:#参数loc(float):正态分布的均值,对应着这个分原创 2021-12-20 20:44:32 · 1708 阅读 · 0 评论 -
Numpy-创建数组
import numpy as np#定义1个一维的元素属性是整型的arraya = np.array([1,2,3],dtype = np.int32)print(a.dtype)int32#定义1个一维的元素属性是浮点型的arrayb = np.array([1,2,3],dtype = np.float)print(b.dtype)float64##定义1个二维的元素属性是整型的arrayd= np.array([[1,2,3],[4,5,6]],dtype = np.int3原创 2021-12-20 20:37:14 · 128 阅读 · 0 评论 -
Numpy-矩阵的运算
import numpy as nparr1 = np.array([[2,2,2], [4,4,4]])arr2 = np.array([[9,9,9], [1,1,1]])print(arr1)[[2 2 2] [4 4 4]]print(arr2)[[9 9 9] [1 1 1]]#矩阵加法:按位相加,相同位置的元素进行相加print(arr1 + arr2)[[11 11 11] [ 5 5 5]]原创 2021-12-20 20:34:06 · 505 阅读 · 0 评论 -
Numpy学习-数组的索引
import numpy as nparr1 = np.arange(2,14)print(arr1)#[ 2 3 4 5 6 7 8 9 10 11 12 13]#提取矩阵中某个索引的值print(arr1[2])#4#提取矩阵中索引片段的值print(arr1[1:4])#[3 4 5]print(arr1[2:-1])#[ 4 5 6 7 8 9 10 11 12]print(arr1[:5])#前5个数据#[2 3 4 5 6]print(arr1[原创 2021-12-20 20:27:09 · 294 阅读 · 0 评论