iPython: Create variables that depend on the loop index -
dear stackoverflow community,
i new programming please excuse if not answers , have ask again. tried use search function , pretty sure problem common one, not understand answers honest.
i using ipython 1.1.0 run program named cantera, combustion modelling. runs python 2.7 if correct. problem want plot multiple data points via matplotlib getting these datapoints seems kind of hard. want show dependance of 2 specific combustion variables. approach create loop , every step create 1 of these datapoints , and plot of them in end. tried create variables depend on index name turns out code used not work.
%matplotlib inline import matplotlib.pyplot plt import numpy nm future import division import cantera ct
for in range(50,151): x_i = i/100
the thing every loop overwrites existing variable x_i end 1 variable x_i in end. want every loop create new variable x_1, x_2 x_3, x_4 , on. there easy way that?
thank help.
use dictionary:
x={} in range(50,151): x[i] = i/100
or list
x=[] in range(50,151): x.append(i/100)
Comments
Post a Comment