I am very new to python and indexing is still difficult for me. I am trying to plot few values using iterative operation but it seems it is not working and giving me above error. Please help me. Thanks.
My code:
import numpy as np
import matplotlib.pyplot as mp
e = np.exp
z = np.arange(1000)
for i in z:
while True:
H_2 = 0.58*e(-(z[i]/81)**2)
i += 1
mp.scatter(H_2 , z, c = 'r')
mp.show()
This line is giving you the error i += 1
If you plan on using the while loop, don't forget to add your break statement, otherwise you'll be stuck in an infinite loop. Without any additional details, I don't see why it is necessary in this case.
In addition to that, I would define H_2 as an empty list, and append any values in your calculation to it. According to the documentation, H_2 needs to be an array-like value.
So it should look like:
import numpy as np
import matplotlib.pyplot as mp
e = np.exp
z = np.arange(1000)
H_2 = []
for i in z:
H_2.append(0.58*e(-(i/81)**2))
mp.scatter(H_2 , z, c = 'r')
mp.show()
Hopefully the graph appears as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With