import pickle
import numpy as np
import time
from numba import njit
@njit
def update_matrix(matrix, indices):
for i in indices:
for j in indices:
matrix[i,j] += 1
# 加载数据的函数
def load_data():
with open(r"D:\python_learn\numpy_matrix.pkl", 'rb') as fo:
data = pickle.load(fo)
return data
if __name__ =="__main__":
data=load_data()
total=np.sum(data, axis=0)#计算每一列的和
matrix_support= np.zeros((data.shape[1], data.shape[1]))
start =time.time()
for row in data:
indices = np.where(row == 1)[0]# 找出每一行中为1的索引
update_matrix(matrix_support, indices) # 使用Numba函数更新矩阵
end = time.time()
print(f" 1耗时{end-start}")