0

I wrote code that returns this in the console:

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().

This is my code.

import numpy as np
import matplotlib.pyplot as plt

lambd= np.linspace(0.0,15000.0, 100) #lambda in angstroms
alpha0=1.0449*10.0**(-26.0) #For lambda in angstroms
R=1.0968*10.0**(-3.0) #angstroms^-1


def g_bf(lambd,n):
    return 1.0-((0.3456/(lambd*R)**(1./3.))*((lambd*R / (n**2.0))-         (0.5)))


def alpha_bf(lambd,n):  
    lamb_0=912.0 #angstroms
    if lambd >= lamb_0:
        return 0.0
    else:
        return alpha0*g_bf(lambd,n)*((lambd**3.0)/(n**5.0))

 a_bf= alpha_bf(lambd,1.0)
 plt.plot(lambd, a_bf)

What do I have to do?

paisanco
  • 4,098
  • 6
  • 27
  • 33
Alan AS
  • 1
  • 1
  • 3
    *"What do I have to do?"* - Use a.any() or a.all(). – Stefan Pochmann Sep 15 '16 at 01:59
  • 1
    [`np.linspace()` returns an array](http://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html), in your code it looks like 100 samples. It doesn't make sense to write `if lambd >= lamb_0` when lambd is a 100 element array. I have my suspicions that numpy overloads the `>=` operator, but all major search engines don't have a "search for what I typed in" feature, so I haven't managed to confirm or deny it. – TessellatingHeckler Sep 15 '16 at 02:09

0 Answers0