This commit is contained in:
guanjihuan 2022-03-16 19:37:32 +08:00
parent 3f91ca3bdd
commit 27cafcd10c
9 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,2 @@
import cmath
print(cmath.exp(1j*cmath.pi))

View File

@ -0,0 +1,26 @@
import copy
import numpy as np
array_1 = [1, 2, 3]
array_2 = array_1
array_1[0] = 100
print('array_1=', array_1)
print('array_2=', array_2, '\n')
array_1 = np.array([1, 2, 3])
array_2 = array_1
array_1[0] = 100
print('array_1=', array_1)
print('array_2=', array_2, '\n')
array_1 = [1, 2, 3]
array_2 = copy.deepcopy(array_1)
array_1[0] = 100
print('array_1=', array_1)
print('array_2=', array_2, '\n')
array_1 = np.array([1, 2, 3])
array_2 = copy.deepcopy(array_1)
array_1[0] = 100
print('array_1=', array_1)
print('array_2=', array_2)

View File

@ -0,0 +1,7 @@
import functools
def func(x, y, z):
return x-y+z
partial_func = functools.partial(func, x=5, z=0)
print(partial_func(y=2))

View File

@ -0,0 +1,13 @@
import math
print(math.pi)
print(math.e)
print(math.exp(1))
print(math.cos(math.pi))
print(math.sqrt(2), '\n')
import numpy as np
print(np.pi)
print(np.e)
print(np.exp(1))
print(np.cos(np.pi))
print(np.sqrt(2))

View File

@ -0,0 +1,8 @@
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(range(10), range(10))
ax.set_title('Example', fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel('x', fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel('y', fontsize=20, fontfamily='Times New Roman')
plt.show()

View File

@ -0,0 +1,23 @@
from multiprocessing import Process
import time
def f(name):
time.sleep(5)
print('Hello', name)
if __name__ == '__main__':
start_time = time.time()
p1 = Process(target=f, args=('Bob',))
p2 = Process(target=f, args=('Alice',))
p1.start()
p2.start()
p1.join()
p2.join()
end_time = time.time()
print(end_time - start_time, '\n')
start_time = time.time()
f('Bob')
f('Alice')
end_time = time.time()
print(end_time - start_time)

View File

@ -0,0 +1,21 @@
import numpy as np
np.zeros((2, 3)) # 零矩阵
np.identity(3) # 单位矩阵
np.diag([1, 3, 5]) # 对角矩阵
matrix1 = np.array([[3, 5+1j], [2, 7]]) # numpy矩阵
matrix1.shape # 矩阵的维度
matrix1.transpose() # 矩阵转置
matrix1.conj() # 矩阵所有元素共轭
np.conj(matrix1) # 矩阵所有元素共轭(同上)
np.arange(1, 5, 1) # 数列(左闭右开)
np.linspace(-2, 2, 5) # 数列(左闭右闭)
np.random.uniform(-2, 2) # 随机数
np.random.randint(0, 2) # 随机整数(左闭右开)
np.sort([1, 7, 0, 3]) # 排列
np.argsort([1, 7, 0, 3]) # 排列索引
np.linalg.det(matrix1) # 行列式
matrix2 = np.linalg.inv(matrix1) # 求逆
np.matmul(matrix1, matrix2) # 矩阵乘积
np.dot(matrix1, matrix2) # 矩阵乘积(同上)
eigenvalue, eigenvector = np.linalg.eig(matrix1) # 求本征值,本征向量
matrix3 = np.append(matrix1, matrix2, axis=0) # 增加数组元素或者矩阵的行

View File

@ -0,0 +1,6 @@
import os
os.getcwd() # 获取路径
if os.path.exists('new_dir') == False: # 判断路径是否存在
os.makedirs('new_dir') # 新建文件夹
os.chdir('new_dir') # 切换到该文件夹
print(os.walk('/')) # 游走目录

View File

@ -0,0 +1,5 @@
import time
start_time = time.time()
time.sleep(5)
end_time = time.time()
print(end_time-start_time)