numpy100问1-50问代码
这儿只是当一个代码留存
1-25问哔哩哔哩视频地址 https://www.bilibili.com/video/BV1c54y1U72h
25-50问哔哩哔哩视频地址 https://www.bilibili.com/video/BV1vA411Y7di
# print(sum(range(5),-1))# 第26题测试
import numpy as np
# print(np.__version__)
# np.show_config()
# a = np.empty((1,10))
# print(a)
# b = np.empty(10)
# print(b)
# print(a.size*a.itemsize)
# np.info(np.add)
# a[0, 4] = 1
# print(a)
# Z = np.arange(10,50)
# print(Z)
# a = np.random.randint(10, 50, (3,2))
# print(a)
# a = np.random.randint(10, 50, (3,5))
# print(a)
# b = a[:,::-1] #其中[::-1]代表从后向前取值,每次步进值为1
# print(b)
# c = a[::-1,:]
# print(c)
# a = np.random.randint(0, 9, (3,3))
# print(a)
# Z = np.arange(9).reshape(3,3)
# print(Z)
# nz = np.nonzero([1,2,0,0,4,0])
# print(nz)
# a = np.eye(3)
# print(a)
# a = np.random.random((3,3,3))
# print(a)
# a = np.random.random((10,10))
# print(a.max())
# print(a.min())
# print(np.amax(a))
# print(np.amin(a))
# a = np.random.random(30)
# print(a.mean())
# print(np.mean(a))
# Z = np.ones((10,10))
# Z[1:-1,1:-1] = 0
# print(Z)
# Z = np.ones((5,5))
# Z = np.pad(Z, pad_width=1, mode='constant', constant_values=0)
# print(Z)
# print(0 * np.nan)
# print(np.nan == np.nan)
# print(np.inf > np.nan)
# print(np.nan - np.nan)
# print(0.3 == 3 * 0.1)
# Z = np.diag(1+np.arange(4),k=-1)
# print(Z)
# Z = np.zeros((8,8),dtype=int)
# Z[1::2,::2] = 1
# Z[::2,1::2] = 1
# print(Z)
# print(np.unravel_index(100,(6,7,8)))
# a = np.array([[0,1],[1,0]])
# print(a)
# Z = np.tile( np.array([[0,1],[1,0]]), (4,4))
# print(Z)
# Z = np.random.random((5,5))
# Zmax, Zmin = Z.max(), Z.min()
# Z = (Z - Zmin)/(Zmax - Zmin)
# print(Z)
# color = np.dtype([("r", np.ubyte, 1),
# ("g", np.ubyte, 1),
# ("b", np.ubyte, 1),
# ("a", np.ubyte, 1)])
# print(color)
# Z = np.dot(np.ones((5,3)), np.ones((3,2)))
# print(Z) #点乘就是直接的 * 号
# Z = np.arange(11)
# print(Z)
# Z[(3 < Z) & (Z <= 8)] *= -1 #a *= 4 等价于 a = a*4
# print(Z)
# from numpy import *
# print(sum(range(5),-1))
# print(np.array(0) / np.array(0))
# print(np.array(0) // np.array(0))
# print(np.array([np.nan]).astype(int).astype(float))
# Z = np.random.uniform(-10,+10,10) # 产生均匀分布的数组
# print(Z)
# print (np.abs(Z))
# print (np.ceil(np.abs(Z))) # ceil 向上取整
# print (np.copysign(np.ceil(np.abs(Z)), Z)) # np.copysign(a, b) : 将b中各元素的符号赋值给数组a的对应元素
# Z1 = np.random.randint(0,10,10)
# print(Z1)
# Z2 = np.random.randint(0,10,10)
# print(Z2)
# print(np.intersect1d(Z1,Z2))
# yesterday = np.datetime64('today', 'D') - np.timedelta64(1, 'D')
# today = np.datetime64('today', 'D')
# tomorrow = np.datetime64('today', 'D') + np.timedelta64(1, 'D')
# print ("Yesterday is " + str(yesterday))
# print ("Today is " + str(today))
# print ("Tomorrow is "+ str(tomorrow))
# Z = np.arange('2015-02', '2015-03', dtype='datetime64[D]')
# print(Z)
# Z = np.random.uniform(0,10,10)
# print (Z - Z%1)
# print (np.floor(Z))
# print (np.ceil(Z)-1)
# print (Z.astype(int))
# print (np.trunc(Z)) # 向接近于0的方向取整
# Z = np.zeros((5,5))
# Z += np.arange(5)
# print (Z)
# a = np.random.randint(0,5,(1*5))
# print(a)
# b = np.tile(a, (5,1))
# print(b)
# def generate():
# for x in range(10):
# yield x
# Z = np.fromiter(generate(),dtype=float,count=-1)
# print (Z)
# Z = np.linspace(0,1,11,endpoint=False)
# print(Z)
# a = Z[1:]
# print (a)
# Z = np.random.random(10)
# print(Z)
# Z.sort()
# print (Z)
# Z = np.arange(10)
# print(np.add.reduce(Z))
# A = np.random.randint(0,2,5)
# B = np.random.randint(0,2,5)
# # Assuming identical shape of the arrays and a tolerance for the comparison of values
# equal = np.allclose(A,B)
# print(equal)
# equal = np.array_equal(A,B)
# print(equal)
# Z = np.zeros(10)
# Z.flags.writeable = False
# Z = np.random.random((10,2))
# X,Y = Z[:,0], Z[:,1]
# R = np.sqrt(X**2+Y**2)
# T = np.arctan2(Y,X)
# print (R)
# print (T)
# a = np.random.random(10)
# print(a)
# print(a.max())
# a[a.argmax()] = 1
# print(a)
# Z = np.zeros((5,5), [('x',float),('y',float)])
# Z['x'], Z['y'] = np.meshgrid(np.linspace(0,1,5), np.linspace(0,1,5))
# print(Z)
# Z['x'], Z['y'] = np.meshgrid([0,0.3,0.5,0.7,1], [0,0.3,0.5,0.7,1])
# print(Z)
# X = np.arange(8)
# Y = X + 0.5
# C = 1.0 / np.subtract.outer(X, Y)
# print(np.linalg.det(C)) #求行列式
# Z = np.arange(100)
# v = np.random.uniform(0,100)
# print(Z)
# print(v)
# index = (np.abs(Z-v)).argmin()
# print (Z[index])
a = np.array(([7,4,1],[2,5,7],[4,7,7]))
itemindex = np.argwhere(a == 7)
index = np.where(a == 7)
print (itemindex)
print(index)
print (a)
[video(video-evh4nE0O-1597392885510)(type-bilibili)(url-https://player.bilibili.com/player.html?aid=839193559)(image-https://ss.csdn.net/p?http://i0.hdslb.com/bfs/archive/ff8ebf8c910a169a21f967cd08278305ac54fb6f.jpg)(title-numpy)]
[video(video-fjzcfz2X-1597392848481)(type-bilibili)(url-https://player.bilibili.com/player.html?aid=329153676)(image-https://ss.csdn.net/p?http://i2.hdslb.com/bfs/archive/88f908dac0f00d6ef0626ed23f96ba8aa9aa13c9.jpg)(title-numpy100问26-50)]