[Tutor] anomaly

D.V.N.Sarma డి.వి.ఎన్.శర్మ dvnsarma at gmail.com
Fri Apr 20 00:53:37 EDT 2018


I have a situation in which the same code gives an error in idle but works
in qtconsole
regards,

*​in idle*
v = np.zeros(len(x))

for i in range(len(x)):
    if x[i] < 1.0:
        v[i] = 0
    else:
        v[i] = V
print v​

======== RESTART: C:\Users\SHARMA\Documents\Python Scripts\sqwell.py
========

Traceback (most recent call last):
  File "C:\Users\SHARMA\Documents\Python Scripts\sqwell.py", line 45, in
<module>
    if x[i] < 1.0:
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()

​*in qtconsole​*

v = np.zeros(len(x))

for i in range(len(x)):
    if x[i] < 1.0:
        v[i] = 0
    else:
        v[i] = V
print v

[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0. 20. 20. 20. 20.
 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20.
 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20.
 20. 20. 20. 20. 20. 20. 20. 20. 20. 20.]

Sarma.


More information about the Tutor mailing list