1、索引
一维数组与列表完全一致,多维时同理
import numpy as np
nd1 = np.random.randint(0,10,size=3)#array([9, 1, 0])
nd1[1]#1
nd2 = np.random.randint(0,100,size=(2,3))#array([[80, 80, 95],[ 0, 38, 29]])
nd2[1][1]#38也可以写成下面的格式:
nd2[1,1]#38
2、根据索引修改数据
nd2 = np.random.randint(0,10,size=(2,3))#array([[0, 2, 9],[5, 0, 5]])
nd2[1,0]=100#array([[ 0, 2, 9], [100, 0, 5]])
nd3= np.random.randint(0,10,size=3)#array([7, 3, 8])
nd3[1]=100#array([ 7, 100, 8])
3、切片
一维数组与列表完全一致,多维时同理

将数据反转
对一维数组反转

对二维数组反转


网友评论