For the following code:
G = [
[8.29187396e-04,4.98341625e-01,8.29187396e-04,4.98341625e-01,8.29187396e-04,8.29187396e-04],
[4.99168745e-01,4.15627598e-04,2.49792186e-01,4.15627598e-04,2.49792186e-01,4.15627598e-04],
[1.66666667e-01,1.66666667e-01,1.66666667e-01,1.66666667e-01,1.66666667e-01,1.66666667e-01],
[6.65005537e-01,3.32779623e-01,5.53709856e-04,5.53709856e-04,5.53709856e-04,5.53709856e-04],
[1.66666667e-01,1.66666667e-01,1.66666667e-01,1.66666667e-01,1.66666667e-01,1.66666667e-01],
[1.65016502e-03,1.65016502e-03,1.65016502e-03,1.65016502e-03,9.91749175e-01,1.65016502e-03],
]
fnames = ['angelinajolie.html', 'bradpitt.html', 'jenniferaniston.html',
'jonvoight.html', 'martinscorcese.html', 'robertdeniro.html']
NX = len(fnames)
PI = random(NX)
PI /= sum(PI)
import matplotlib.pyplot as plt
evolution = [numpy.dot (PI, G**i) for i in xrange(1,20)]
plt.figure()
for i in xrange(NX):
plt.plot([step[0,i] for step in evolution], label=fnames[i], lw=2 )
# ^ this line
#plt.draw
IndexError: invalid index
Im getting this error. Im learning Python and Im not very familiar with the language. Googling this error didnt give any specific solutions. Wondering if someone can help.
Thanks
EDIT:
I tried the following code
import matplotlib.pyplot as plt
evolution = [numpy.dot (PI, G**i) for i in xrange(1,20)]
print 'xrange'
print xrange(1,20)
print ''
print 'evolution = '
print evolution
print ''
for i in xrange (NX):
print (step[0,i] for step in evolution)
And got this output:
xrange
xrange(1, 20)
evolution =
[array([ 0.32804667, 0.21757686, 0.12538595, 0.15799482, 0.12910639,
0.04188931]), array([ 0.16964679, 0.08472597, 0.02780032, 0.06486529, 0.0314962 ,
0.00690881]), array([ 0.09553784, 0.03664288, 0.00636997, 0.03003363, 0.01003537,
0.00115142]), array([ 0.05605324, 0.01678453, 0.00149546, 0.01458511, 0.00513061,
0.0001919 ]), array([ 3.37327444e-02, 7.93664097e-03, 3.57601326e-04,
7.20471786e-03, 3.96276140e-03, 3.19838999e-05]), array([ 2.06957198e-02, 3.82337165e-03, 8.66673387e-05,
3.57980255e-03, 3.66208187e-03, 5.33064999e-06]), array([ 1.29011406e-02, 1.86325141e-03, 2.12057110e-05,
1.78219658e-03, 3.56712012e-03, 8.88441665e-07]), array([ 8.15011563e-03, 9.14821461e-04, 5.22316873e-06,
8.87848064e-04, 3.52188086e-03, 1.48073611e-07]), array([ 5.20576887e-03, 4.51378732e-04, 1.29239804e-06,
4.42402535e-04, 3.48893476e-03, 2.46789351e-08]), array([ 3.35501606e-03, 2.23446508e-04, 3.20779482e-07,
2.20459413e-04, 3.45918721e-03, 4.11315586e-09]), array([ 2.17777263e-03, 1.10856782e-04, 7.97863000e-08,
1.09862738e-04, 3.43040772e-03, 6.85525976e-10]), array([ 1.42161006e-03, 5.50797457e-05, 1.98730096e-08,
5.47489480e-05, 3.40204477e-03, 1.14254329e-10]), array([ 9.32090403e-04, 2.73937246e-05, 4.95462506e-09,
2.72836418e-05, 3.37396034e-03, 1.90423882e-11]), array([ 6.13212265e-04, 1.36332014e-05, 1.23604372e-09,
1.35965681e-05, 3.34611871e-03, 3.17373137e-12]), array([ 4.04478562e-04, 6.78792560e-06, 3.08490244e-10,
6.77573479e-06, 3.31850955e-03, 5.28955228e-13]), array([ 2.67327741e-04, 3.38068736e-06, 7.70144829e-11,
3.37663051e-06, 3.29112888e-03, 8.81592047e-14]), array([ 1.76949431e-04, 1.68406555e-06, 1.92302878e-11,
1.68271551e-06, 3.26397429e-03, 1.46932008e-14]), array([ 1.17260538e-04, 8.39016441e-07, 4.80235424e-12,
8.38567176e-07, 3.23704380e-03, 2.44886680e-15]), array([ 7.77733433e-05, 4.18042435e-07, 1.19938700e-12,
4.17892928e-07, 3.21033551e-03, 4.08144466e-16])]
xrange(NX) =
xrange(6)
<generator object <genexpr> at 0x10c1b9f50>
<generator object <genexpr> at 0x10c1b9f50>
<generator object <genexpr> at 0x10c1b9f50>
<generator object <genexpr> at 0x10c1b9f50>
<generator object <genexpr> at 0x10c1b9f50>
<generator object <genexpr> at 0x10c1b9f50>
evolutionandfnamesare.plt.plotcall with aprintthat outputsiand parameters you pass toplt.plot. Run the loop, see if it works. If it does not, you will at least see the value ofiwhen it last worked; it may help you. The example you provided works fine for me with plotting calls removed.