import numpy as np
a = np.array([1,2,3,4])
print(a)
b = np.array([[1,2],[3,4],[5,6]])
print(b)
b.ndim
b.shape
b.dtype
c = np.arange(10)
print(c)
d = np.linspace(0,2,11)
print(d)
np.ones((3,3))
np.ones((2,3,3))
np.zeros((3,6))
np.eye(4)
np.eye(4,4,-2)
np.random.randn(6,4)
a = np.arange(10)
a[::3]
a = np.arange(0,51,10).reshape(6,1)+ np.arange(6)
print(a)
a = np.random.randint(10,20,6)
print(a)
b = (a % 2 == 0)
print(b)
c = a[a %2 ==0]
print(c)
a = np.arange(0,51,10).reshape(6,1)+ np.arange(6)
a[a % 2==0]
a = np.arange(6)
b = a[2:5]
b[1] = 100
print(a,b)
print("a,b共享状态是:",np.may_share_memory(a,b))
c = a[2:5].copy()
c[1] = 101
print (a,b, c)
print("a,c共享状态是:",np.may_share_memory(a,c))
a = np.arange(1,101)
n_max = int(np.sqrt(len(a)))
is_prime = np.ones(len(a),dtype = bool)
print(len(is_prime))
is_prime[0] = False
for i in range(2,n_max):
print(i)
for i in a[is_prime]:
is_prime[(i**2-1)::i] = False
print(a[is_prime])
a = np.arange(1,101)
n_max = int(np.sqrt(len(a)))
is_prime = np.ones(len(a),dtype = bool)
print(len(is_prime))
is_prime[0] = False
for i in range(2,n_max):
print(i)
for i in a[is_prime]:
is_prime[(i**2-1)::i] = False
print(a[is_prime])
a = np.arange(6)
print(a+5)
b = np.random.randint(1,5,20).reshape(4,5)
print(b,b*3)
a = np.random.randint(1,5,(5,4))
b = np.ones((5,4),dtype = int)
print(a,b,a+b,a*b)
a = np.random.randint(1,5,(3,2))
b = np.random.randint(1,5,(2,3))
print(a,b, np.dot(a,b))
a = np.random.randint(1,5,(5,4))
b = np.arange(4)
print(a,b,a+b)
c = np.arange(5).reshape(5,1)
print(a,c,a+c)
a = np.array([1,2,3,4])
b = np.array([1,2,3,4])
print(a==b)
print(a>=b)
print((a==b).all())
print((a>=b).any())
a = np.arange(6)
print(a,np.cos(a),np.exp(a),np.sqrt(a),sep="\n")
a = np.random.randint(1,5,6)
print(a,a.sum(),a.mean(),a.std(),a.min(),a.max(),a.argmin(),a.argmax(),np.median(a),sep="\n")
counts = np.bincount(a)
print(counts)
print(np.argmax(counts))
b = np.random.randint(1,5,(6,4))
print(b,b.sum(),b.sum(axis=0),b.sum(axis=1),b.sum(axis=1).sum(),sep="\n")
print("******")
print(b.max(axis=0),b.max(axis=1),b.argmin(axis=1),b.std(axis=1),sep="\n")
a = np.random.randint(0,101,(10,3))
print(a)
print("a均值是:",a.mean())
print(a.mean(axis=1))
print(a.mean(axis=0))
import numpy as np
arr2 = np.arange(12).reshape(3,4)
print(arr2)
values1 = np.loadtxt(r"numpyData.txt", delimiter=" ",
unpack=False,dtype=int)
print(values1)
values2 = np.loadtxt(r"numpyData.txt",delimiter=" ",usecols=(1,3),unpack=False)
print(values2)