0
sigma_n = np.array([0.01, 0.1])

ls = np.array([0.1, 0.2])

for sigma_ni in sigma_n:
    for ls_i in ls:
        print("{},{}".format(sigma_ni, ls_i))

I was hoping to find out if there is any way I could print out the above in a pythonic way instead of 2 loops.

quamrana
  • 37,849
  • 12
  • 53
  • 71

2 Answers2

1

You can use itertools.product -

from itertools import product

items = product(sigma_n, ls)

for i in items:
    print(i)
Akshay Sehgal
  • 18,741
  • 3
  • 21
  • 51
0

Look like your printing meshgrid

print(np.meshgrid(sigma_n, ls)

[array([[0.01, 0.1 ],
       [0.01, 0.1 ]]), 
array([[0.1, 0.1],
       [0.2, 0.2]])]
Kenan
  • 13,156
  • 8
  • 43
  • 50