Python Forum

Full Version: for loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have this code and I want obtained all the possible values of the matrix X:

import numpy as np

for i in range (10):
    
  x1 = -10 +(0.1)*(i-1)
  print (x1)
for j in range (10):  
   x2 = -10 +(0.1)*(j-1)
   print (x2)
   
X= np.array([x1, x2])
print(X)
my problem I just obtain the last possibility .

Output:
-10.1 -10.0 -9.9 -9.8 -9.7 -9.6 -9.5 -9.4 -9.3 -9.2 -10.1 -10.0 -9.9 -9.8 -9.7 -9.6 -9.5 -9.4 -9.3 -9.2 [-9.2 -9.2] >>>
Please who can help me
I am not 100% sure I understand what you require, but I believe you want the for j in range (10): loop to be an inner loop (indented with respect to) of the for i in range (10): loop. The line X= np.array([x1, x2]) is outside of the for loops, so it is executed after the loops have finished iterating. You probably want that line inside the inner for loop.
OK , Thank you