I'm running some code where in the middle I have this line:
e2 = np.exp(dot1)
If I print out the value dot1
, it is:
[[-30.248272500719885]]
But the line produces this error:
e2 = np.exp(dot1)
AttributeError: exp
If I go to a new window and simply code this:
print numpy.exp([[-30.248272500719885]])
there are no problems... then what's wrong with the above code?
Edit
I've added some surrounding code to the original line:
import numpy as np
# LOTS OF CODE INCLUDING THE INITIALIZATION OF ARRAYS y and self.g
# AND getting into into a loop with index i
for j in range(m):
print "Calculating beta for class %d ..." % j
f.write("Calculating beta for class "+str(j)+" ...\n")
for i in range(self.no_samples):
i_class = y[i]
X1 = self.X[i].reshape(1, self.no_features)
g1 = self.g[:,j].reshape(self.no_features, 1)
gc = self.g[:,i_class].reshape(self.no_features, 1)
dot = 1. + np.dot(X1, g1) - np.dot(X1,gc)
e = math.exp(dot)
sum_e = 0.
for j2 in range(m): # calculating sum of e's except for all j except where j=i_class
if j2 != i_class: # g based on j2
g2 = self.g[:,j2].reshape(self.no_features, 1)
dot1 = 1. + np.dot(X1, g2) - np.dot(X1,gc)
print dot1
e2 = np.exp(dot1) ## THIS IS THE LINE THE ERROR REFERS TO
f.write( str(e2)+"\n")
sum_e = sum_e + e2[0][0]
The line that's apparently causing the error is the 3rd line from the bottom of this chunk.
Earlier, I used math.exp()
as I've already used it a few lines above... but then I got an overflow error, here: math overflow for a not very overflowing calculation in python