在Python中,在矩阵内进行计算时,如何知道进度或如何显示进度条?

huangapple go评论89阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年5月25日 05:20:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76327471.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定