![]() |
for loop - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: for loop (/thread-14615.html) |
for loop - nesrine - Dec-09-2018 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 . Please who can help me
RE: for loop - j.crater - Dec-09-2018 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.
RE: for loop - nesrine - Dec-09-2018 OK , Thank you |