07其他方式创建数组
zeros创建数组
def zerosTest():
a = np.zeros(5)
print(a)
b = np.zeros(5, dtype = int)
print(b)
c = np.zeros((3, 4))
print(c)
zerosTest()
ones创建数组
def onesTest():
a = np.ones(5)
print(a)
b = np.ones(5, dtype = int)
print(b)
c = np.ones((3, 4))
print(c)
onesTest()
empty创建数组
def emptyTest():
a = np.empty(8)
print(a)
b = np.empty((3, 4), dtype = int)
print(b)
c = np.empty((3, 4))
print(c)
emptyTest()
linspace创建等差数组
def linspaceTest():
a = np.linspace(1, 10, 10)
print(a)
b = np.linspace(10, 20, 5, endpoint =False)
print(b)
linspaceTest()
logspace创建等差数组
def logspaceTest():
a = np.logspace(0, 9, 10, base = 2)
print(a)
b = np.logspace(10, 20, 5, endpoint = True)
print(b)
logspaceTest()