“Ejecute el código de Python Line by Line Online” Código de respuesta

compilador de pitón en línea

Use this site
https://repl.it/languages/python3
Erorri Motrali

Ejecute el código de Python Line by Line Online

import multiprocessing as mp
import numpy as np
import time

def general_func(i, param1, param2, param3):
    output = param1 ** 2 * param2 + param3
    time.sleep(2)
    return (i, output)

def output_generated(output):
    global outputs
    outputs.append(output)

if __name__ == '__main__':
    print('...................................Running in Serial.....................................')
    params = np.random.random((10, 3)) * 100.0
    outputs = []
    time_in_sec = time.time()
    for i in range(0, params.shape[0]):
        output_generated(general_func(i, params[i, 0], params[i, 1], params[i, 2]))
    print('Time in serial:', time.time() - time_in_sec)
    print(outputs)

    print('...................................Running in Parallel.....................................')
    outputs = []
    time_in_sec = time.time()
    pool = mp.Pool(mp.cpu_count())
    for i in range(0, params.shape[0]):
        pool.apply_async(general_func, args=(i, params[i, 0], params[i, 1], params[i, 2]), callback=output_generated)
    pool.close()
    pool.join()
    print('Time in parallel:', time.time() - time_in_sec)
    print(outputs)

    print("We can see that by running the code in parrallel the number of seconds reduced to more than 3 times")
chua wyron

Ejecute el código de Python Line by Line Online

import numpy as np
n , m = input("Enter the matrix and no of Tasks:").split()
n = int(n)
m = int(m)
list = np.array([[0 for k in range(n)] for k1 in range(n)])
print(list)
final_sol = []
for t in range(m):
  row1, col1 = input("task"+str(t+1)+":row and column: ").split()
  row1 = int(row1)
  col1 = int(col1)
  for k in range(n):
    for k1 in range(n):
      if (row1== (k+1)) or (col1 ==( k1+1)):
        list[k][k1] = 1
  empty_list = []
  for k in range(n):
    for k1 in range(n):
      if list[k][k1] ==0:
        empty_list.append(str(k)+','+str(k1))
  print(list) 
  print(empty_list, " count: ",str(len(empty_list)))
  final_sol.append(str(len(empty_list)))
print("Ans:", final_sol)
S R

Ejecute el código de Python Line by Line Online

import numpy as np
n , m = input("Enter the matrix and no of Tasks:").split()
n = int(n)
m = int(m)
list = np.array([[0 for k in range(n)] for k1 in range(n)])
print(list)
final_sol = []
for t in range(m):
  row1, col1 = input("task"+str(t+1)+":row and column: ").split()
  row1 = int(row1)
  col1 = int(col1)
  for k in range(n):
    for k1 in range(n):
      if (row1== (k+1)) or (col1 ==( k1+1)):
        list[k][k1] = 1
  empty_list = []
  for k in range(n):
    for k1 in range(n):
      if list[k][k1] ==0:
        empty_list.append(str(k)+','+str(k1))
  print(list) 
  print(empty_list, " count: ",str(len(empty_list)))
  final_sol.append(str(len(empty_list)))
print("Ans:", final_sol)
S R

Respuestas similares a “Ejecute el código de Python Line by Line Online”

Preguntas similares a “Ejecute el código de Python Line by Line Online”

Más respuestas relacionadas con “Ejecute el código de Python Line by Line Online” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código