1
    import math
    import matplotlib.pyplot as plt

import numpy as np
hc=1.23984186E3

k=1.3806503E-23

T=(np.linspace(5000,10000,50))

lamb = np.linspace(0.00001,.0000001,50)
print(len(lamb))
print (len(T))

planck_top=8*math.pi*hc
planck_bottom1=lamb*1000000
planck_bottom2=math.exp(hc//lamb*k*T)
planck=planck_top//planck_bottom

I keep getting this error here;

>
planck_bottom2=math.exp(hc//lamb*k*T)
TypeError: only size-1 arrays can be converted to Python scalars

I am not sure how to correct this, as we are dealing with a large array here

dom ryan
  • 27
  • 4

2 Answers2

3

hc//lamb*k*T returns an array, and math.exp() can work with a number only. So, the following would work:

planck_bottom2=[math.exp(i) for i in hc//lamb*k*T]

It returns a list containing each number in the array hc//lamb*k*T correspondingly exponentiated.

Kristada673
  • 3,512
  • 6
  • 39
  • 93
1

You have another option of using numpy instead of math.

Using Numpy for Array Calculations

Just replace math by np since you already import numpy as np.

planck_top=8*np.pi*hc
planck_bottom2 = np.exp(hc//lamb*k*T)

About using math and/or numpy:

As an additional piece of information, I encourage you to look at the following references for evaluating when/if you should choose math and/or numpy.

  1. What is the difference between import numpy and import math [duplicate]
  2. Are NumPy's math functions faster than Python's?
  3. "Math module functions cannot be used directly on ndarrays because they only accept scalar, not array arguments."
CypherX
  • 7,019
  • 3
  • 25
  • 37