导入相关库
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import matplotlib.pyplot as plt
%matplotlib inline
1.创建一个长度为10的一维全为0的ndarray对象,然后让第5个元素等于1
s1=np.zeros(shape=10)
s1
s1[4]=1
s1

2.创建一个元素为从10到49的ndarray对象
np.random.randint(10,50,size=10)
np.linspace(10,49,10)
a=np.arange(10,50)
a

3.使用np.random.random创建一个10*10的ndarray对象,并打印出最大最小元素
a4=np.random.random(size=(10,10))
a4
zmin,zmax=a4.min(),a4.max()
zmin,zmax

4.创建一个10*10的ndarray对象,且矩阵边界全为1,里面全为0
nd = np.zeros(shape=(10,10),dtype=np.int8)
nd[[0,9]]=1
nd[:,[0,9]]=1
nd

5.创建一个每一行都是从0到4的5*5矩阵
l=[0,1,2,3,4]
nd=np.array(l*5)
nd.reshape(5,5)

6.创建一个范围在(0,1)之间的长度为12的等差数列
np.linspace(0,1,12)

7.创建一个长度为10的随机数组并排序
a8=np.random.random(10)
a8
np.sort(a8)
a8.argsort()
a8[a8.argsort()]

8.创建一个长度为10的随机数组并将最大值替换为0
nd=np.random.randint(0,10,size=10)
display(nd)
index_max=nd.argmax()
nd[index_max]
all_index_max=np.argwhere(nd==nd[index_max]).reshape(-1)
all_index_max
nd[all_index_max]=-100
nd

9.根据第3列来对一个5*5矩阵排序?
n10=np.random.randint(0,100,size=(5,5))
n10

10.给定数组[1, 2, 3, 4, 5],如何得到在这个数组的每个元素之间插入3个0后的新数组?
nd1=np.arange(1,6)
nd2=np.zeros(shape=17,dtype=int)
nd2[::4]=nd1
nd2
n12=np.array([1,2,3,4,5]).reshape(5,1)
n12
n12_1=np.zeros((5,3))
n12_1
n12=np.concatenate([n12,n12_1],axis=1)
n12
