AttributeError: 'numpy.ndarray' object has no attribute 'dim'
Iris example - AttributeError: 'numpy.ndarray' object has no attribute 'dim'
Python Neural Network: 'numpy.ndarray' object has no attribute 'dim' - Stack Overflow
Python Coding help- keep recieving error message"AttributeError: 'numpy.ndarray' object has no attribute 'MESSAGE_A'"
https://imgur.com/gallery/yAdAjdx
Hello,
Linked is the screenshot of the two error messages I keep recieving as well as the code leading up to it. I'm trying to run an uplift on a classification tree. Any help is appreciated, I am still fairly new to python. Thank you!!
As described in the comments, it is essential that the output of softmax(scores) be an array, as lists do not have the .T attribute. Therefore if we replace the relevant bits in the question with the code below, we can access the .T attribute again.
num = np.exp(x)
score_len = len(x)
y = np.array([0]*score_len)
It must be noted that we need to use the np.array as non numpy libraries do not usually work with ordinary python libraries.
Look at the type and shape of variables in your code
x is a 1d array; scores is 2d (3 rows):
In [535]: x.shape
Out[535]: (80,)
In [536]: scores.shape
Out[536]: (3, 80)
softmax produces a list of 3 items; the first is the number 0, the rest are arrays with shape like x.
In [537]: s=softmax(scores)
In [538]: len(s)
Out[538]: 3
In [539]: s[0]
Out[539]: 0
In [540]: s[1].shape
Out[540]: (80,)
In [541]: s[2].shape
Out[541]: (80,)
Were you expecting softmax to produce an array with the same shape as its input, in this case a (3,80).
num=np.exp(scores)
res = np.zeros(scores.shape)
for i in range(1,3):
res[i,:]= num[i,:]/sum(num)
creates a 2d array that can be transposed and plotted.
But you shouldn't have to do this row by row. Do you really want the 1st row of res to be 0?
res = np.exp(scores)
res = res/sum(res)
res[0,:] = 0 # reset 1st row to 0?
Why were you doing a vectorized operation on each row of scores, but not on the whole thing?