Home > Mobile >  How to make this script more efficient
How to make this script more efficient

Time:08-09

How would I make this script more efficient to achieve the exact same output plot? Ie, reduce the number of for loops etc. Ideas that come to mind are list comprehension, lambda expressions, "*="...

import numpy as np
import matplotlib.pyplot as plt

l = [1,2,3,4,5]
l = np.array(l)
l2 = [10,20,30,40,50]
l2 = np.array(l2)

t = [3,4,5]

f = []
for i in t:
    l1=l*(i)
    f.append(l1)
    
for i in range(len(f)):
    plt.plot(l1, f[i])
    
f = []
for i in t:
    l3=l2*(i)
    f.append(l3)

for i in range(len(f)):
    plt.plot(l3, f[i])

CodePudding user response:

  1. Use enter image description here

  • Related