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'"
tensorflow - AttributeError: 'numpy.ndarray' object has no attribute 'op' - Stack Overflow
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?
Hi,
I'm trying to create a numpy v-stack and creating 3 np.array's for it, by filling them with a loop:
I get the error: 'AttributeError: 'numpy.ndarray' object has no attribute 'np' . I think I'm using the wrong notation to append to the empty arrays:
neighbor_id = [id_ for id_ in range(1, n_obs) if id_ != user_id]
neighbor_id_arr = np.array(neighbor_id)
similarity = np.array([])
num_interactions = np.array([])
# get similarity and num_interactions
for id_ in neighbor_id:
similarity.np.append(np.dot(user_item.loc[user_id],user_item.loc[id_])) #The issue is here, I think
num_interactions.np.append(user_interactions.loc[id_])
c = numpy.vstack((neighbor_id_arr, similarity,num_interactions))
Thanks!
James