标签:数字 运算 mat read concat 执行 sha plot info
import numpy as np arr_1 = np.array([1,2,3]) arr_1
array([1, 2, 3])
np.array([[1,2,3],[4,5,6]])
array([[1, 2, 3],
[4, 5, 6]])
np.array([[1,2,3],[4,5.5,6]])
array([[1. , 2. , 3. ],
[4. , 5.5, 6. ]])
import matplotlib.pyplot as plt img_arr = plt.imread(‘../imglibs/Aerith艾瑞丝 女孩子 花 唯美插图4k高清动漫壁纸.jpg‘) plt.imshow(img_arr)
plt.imshow(img_arr-20)
np.ones(shape=(3,4))
array([[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]])
np.linspace(1,100,num=20) #等差数列
array([ 1. , 6.21052632, 11.42105263, 16.63157895,
21.84210526, 27.05263158, 32.26315789, 37.47368421,
42.68421053, 47.89473684, 53.10526316, 58.31578947,
63.52631579, 68.73684211, 73.94736842, 79.15789474,
84.36842105, 89.57894737, 94.78947368, 100. ])
np.arange(1,100,step=5) #等差数列
array([ 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81,
86, 91, 96])
np.random.randint(0,100,size=(5,6))
创建一个5行六列得二维数组
array([[24, 30, 72, 15, 0, 54],
[22, 78, 50, 16, 52, 42],
[98, 39, 74, 98, 54, 0],
[85, 11, 52, 32, 89, 33],
[79, 85, 1, 19, 0, 47]])
bobo_arr.shape #返回数组的形状
(626, 413, 3)
bobo_arr.ndim #返回数组的维度
3
bobo_arr.size #返回数组元素的个数
775614
bobo_arr.dtype #返回的是数组元素的数据类型
dtype(‘uint8‘)
arr = np.array([1,2,3],dtype="int64") arr.dtype
对数据进行强转类型
dtype(‘int64‘)
arr.dtype
dtype(‘float32‘)
arr = np.random.randint(0,100,size=(4,6)) arr
array([[ 2, 57, 40, 33, 96, 65],
[69, 36, 33, 12, 64, 54],
[12, 1, 10, 30, 51, 67],
[26, 32, 10, 21, 84, 39]])
创建一个0~100得随机数二维数组为4行6列
arr[2]
array([12, 1, 10, 30, 51, 67])
#切出前两行数据 arr[0:2]
array([[ 2, 57, 40, 33, 96, 65],
[69, 36, 33, 12, 64, 54]])
#切出前两列数据 arr[:,0:2] #逗号左边是数组的第一个维度,右边是第二个维度
array([[ 2, 57],
[69, 36],
[12, 1],
[26, 32]])
#切出前两行的前两列 arr[0:2,0:2]
array([[ 2, 57],
[69, 36]])
#行进行倒置 arr[::-1]
array([[ 2, 57],
[69, 36]])
#列倒置 arr[:,::-1]
反转行
array([[65, 96, 33, 40, 57, 2],
[54, 64, 12, 33, 36, 69],
[67, 51, 30, 10, 1, 12],
[39, 84, 21, 10, 32, 26]])
arr[::-1,::-1]
反转列行
array([[39, 84, 21, 10, 32, 26],
[67, 51, 30, 10, 1, 12],
[54, 64, 12, 33, 36, 69],
[65, 96, 33, 40, 57, 2]])
图片也可以进行反转
plt.imshow(img_arr[::-1,::-1])
plt.imshow(img_arr[::-1])
plt.imshow(img_arr[:,::-1,:])
plt.imshow(img_arr[::-1,::-1,::-1])
arr.reshape(6,4)
把数据转换为6行4列得数组
array([[22, 51, 3, 30],
[24, 96, 87, 91],
[39, 43, 69, 57],
[33, 49, 29, 72],
[98, 98, 37, 49],
[15, 48, 29, 38]])
arr.reshape((2,-1)
把数据转换为12列2行得数组不能随便转换必须等列等行
array([[22, 51, 3, 30, 24, 96, 87, 91, 39, 43, 69, 57],
[33, 49, 29, 72, 98, 98, 37, 49, 15, 48, 29, 38]])
np.concatenate((arr,arr),axis=1)
合并数组列
array([[22, 51, 3, 30, 24, 96, 22, 51, 3, 30, 24, 96],
[87, 91, 39, 43, 69, 57, 87, 91, 39, 43, 69, 57],
[33, 49, 29, 72, 98, 98, 33, 49, 29, 72, 98, 98],
[37, 49, 15, 48, 29, 38, 37, 49, 15, 48, 29, 38]])
np.concatenate((arr,arr),axis=0)
合并数据行
array([[22, 51, 3, 30, 24, 96],
[87, 91, 39, 43, 69, 57],
[33, 49, 29, 72, 98, 98],
[37, 49, 15, 48, 29, 38],
[22, 51, 3, 30, 24, 96],
[87, 91, 39, 43, 69, 57],
[33, 49, 29, 72, 98, 98],
[37, 49, 15, 48, 29, 38]])
arr_1 = np.random.randint(0,100,size=(5,6)) arr_1
array([[14, 12, 7, 39, 43, 62],
[66, 27, 16, 77, 68, 27],
[ 3, 81, 5, 45, 17, 95],
[39, 75, 76, 86, 99, 34],
[56, 4, 96, 96, 30, 59]])
arr_3 = np.concatenate((img_arr,img_arr,img_arr),axis=1) arr_9 = np.concatenate((arr_3,arr_3,arr_3)) plt.imshow(arr_9)
`#### 常用的聚合操作
`#### 常用的数学函数
`#### 常用的统计函数
标签:数字 运算 mat read concat 执行 sha plot info
原文地址:https://www.cnblogs.com/ziweijun/p/13207766.html