英文:
How to do I know the progress or how to show a progress bar when a calculation is being done inside a matrix in Python?
问题
我想知道在Python中在矩阵内进行计算时如何显示进度或如何显示进度条?有人能帮助我吗?
在Python中,在矩阵内进行计算时显示进度条
英文:
I want to know the progress or how to show a progress bar when a calculation is being done inside a matrix in Python? Can someone help me out please?
Show a progress bar when a calculation is being done inside a matrix in Python
答案1
得分: 0
I used numpy.sin as an example for matrix calculation and looped.
我以numpy.sin作为矩阵计算的示例,并进行了循环。
I used also tqdm.
我还使用了tqdm。
Hope the sample code helps:
希望这个示例代码有所帮助:
import numpy as np
from tqdm import tqdm
Define the dimensions of the matrix
定义矩阵的维度
rows = 20000
columns = 20000
Create the matrix (random example)
创建矩阵(随机示例)
matrix = np.random.rand(rows, columns)
Create an empty result matrix
创建一个空的结果矩阵
result = np.zeros((rows, columns))
Iterate over each element of the matrix and show a progress bar
迭代矩阵的每个元素并显示进度条
for i in tqdm(range(rows)):
result[i, :] = np.sin(matrix[i, :]) # Your calculation goes here
# 在这里进行你的计算
Calculation complete
计算完成
print("Matrix calculation finished!")
print(result)
英文:
I used numpy.sin as an example for matrix calculation and looped.
I used also tqdm.
Hope the sample code helps:
import numpy as np
from tqdm import tqdm
# Define the dimensions of the matrix
rows = 20000
columns = 20000
# Create the matrix (random example)
matrix = np.random.rand(rows, columns)
# Create an empty result matrix
result = np.zeros((rows, columns))
# Iterate over each element of the matrix and show a progress bar
for i in tqdm(range(rows)):
result[i, :] = np.sin(matrix[i, :]) # Your calculation goes here
# Calculation complete
print("Matrix calculation finished!")
print(result)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论