Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for loop
#1
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
Reply
#2
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.
Reply
#3
OK , Thank you
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020