AttributeError: 'list' object has no attribute 'toarray' - python

class aSDAE_module():
def get_middle_layer(self,aSDAE,train_user):
middle=self.model.predict({'user_rating':aSDAE,'user_sideinformation':train_user},batch_size=self.batch_size)[2]
return middle
alpha = asdae_module.get_middle_layer(R.toarray(),aSDAE.toarray())
This is my piece of code where I am stuck, and I don't know how to resolve the following error:
Traceback (most recent call last):
File "./run.py", line 142, in <module>
train_user=train_user, train_item=train_item, valid_user=valid_user, test_user=test_user, R=R)
File "/home/hira/Desktop/PHD/PHDMF-master/asdae_models.py", line 52, in PHDMF
alpha = asdae_module.get_middle_layer(R.toarray(),aSDAE.toarray())
AttributeError: 'list' object has no attribute 'toarray'

There is no built-in type 'array' in python, it is not obvious what are you doing in asdae module, but you have to either change the implementation of asdae to work with list type object instead of an array or using Numpy library.
in order to converting list object to Numpy array you can do like this code:
import numpy as np
# converting aSDAE list to an array
aSDAE = np.array(aSDAE)

Related

AttributeError: 'module' object has no attribute 'array'

I am trying to input a matix using numpy and I get the following error:
Traceback (most recent call last):
File "phase1.py", line 1, in <module>
import numpy as np
File "/home/rockstar/phase1.py", line 2, in <module>
a= np.array([1,2,3])
AttributeError: 'module' object has no attribute 'array'
I am not sure why this error is there. Could anyone help?
You probably have a file called numpy.py in the same folder that shadows the real numpy module. Rename your .py file and delete its .pyc file.

TypeError: 'float' object has no attribute '__getitem__' in Python

I am working on a project in Python. I am a beginner and I am getting this error when I am running the program.
Traceback (most recent call last):
File "E:/Python/1616/checkProfile.py", line 104, in <module>
p.getResults()
File "E:\Python\1616\Profile.py", line 67, in getResults
for i in range(2): self._s[1] += e.getS[1]
TypeError: 'float' object has no attribute '__getitem__'
Error in Line 67
http://pastebin.com/HXvppfmU
to check what are the methods allowed for datatypes,
dir(datatype)
# As for float, try dir(float)
#This will suggest you that there is no method called __getitem__ for float.
# You might be trying to get some data or you are using []/()/{} which is not correct.
Try to post ur code.

Type error in python 2.7

Traceback (most recent call last):
File "C:\Python27\meanshift.py", line 15, in <module>
roi = frame[r:r+h, c:c+w],
TypeError: 'NoneType' object has no attribute '__getitem__'
Please help me to resolve this error, I am trying to make a region of interest on the first frame to track an object.
Usually I get this kind of errors if I forgot to put a return statement at the end of a function:
def create_array(n):
a = np.array((n,5))
b = create_array(10)
print b[5,1]
Without an explicit return a at the end of the function, it will return None.

TypeError: 'NoneType' object has no attribute '__getitem__15'

hello to every one, I want ro run camshift algorithm but an error is created during running time. The error is:
Traceback (most recent call last):
File "C:\Python27\code\extra algorithms\Camshift in OpenCV.py", line 11, in <module>
roi = frame[r:r+h, c:c+w] TypeError: 'NoneType' object has no attribute '__getitem__10'
`
Probably frame is None. So you can't index it like you're doing in frame[r:r+h, c:c+w]. You should initialize the variable or handle the case when it's None.

Why scipy.io.wavfile.read does not return a tuple?

I am trying to read a *.wav file using scipy. I do the following:
import scipy
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
As a result of this code I get:
Traceback (most recent call last):
File "test3.py", line 2, in <module>
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
AttributeError: 'module' object has no attribute 'io'
Does anybody know what is wrong here? Thank you in advance.
As the error says, scipy module does not have 'io'.
io.wavfile is a submodule, you need to from scipy.io import wavfile and then do wavfile.read("/usr/share/sounds/purple/receive.wav")
This gives me an error with the file you are using as an example, however...

Categories