You return four variables s1,s2,s3,s4 and receive them using a single variable obj. This is what is called a tuple, obj is associated with 4 values, the values of s1,s2,s3,s4. So, use index as you use in a list to get the value you want, in order.
Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
print obj[3] + " is a benefit of functions!"
Answer from Aswin Murugesh on Stack Overflowpython - I don't know why I keep getting AttributeError: 'tuple' object has no attribute 'size' - Stack Overflow
AttributeError: 'tuple' object has no attribute 'device' for tuple output
tensorflow - getting 'AttributeError: 'tuple' object has no attribute 'dtype'' when using tf.metrics.mean_absolute_error - Stack Overflow
python - AttributeError: 'tuple' object has no attribute 'shape' - Stack Overflow
Videos
You return four variables s1,s2,s3,s4 and receive them using a single variable obj. This is what is called a tuple, obj is associated with 4 values, the values of s1,s2,s3,s4. So, use index as you use in a list to get the value you want, in order.
Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
print obj[3] + " is a benefit of functions!"
You're returning a tuple. Index it.
Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
It appears that the values of split_dict are tuples and not what I assume to be expected np.array's. I would recommend taking a look at what function split is returning to split_dict because it might be creating tuples instead of np.array's.
Edit:
Based on what's inside function split, it's returning {0: (array([0, 2], dtype=int64),), 1: (array([1, 3, 4, 5], dtype=int64),)} to split_dict so the values are tuples that contain a numpy.array and the data type (in this case int64) as elements, thus raising the AttributeError.
A slightly modified split that does what you're looking for would look something like this:
def split(array):
N={}
uniqe_array=np.unique(array)
for i in uniqe_array:
N[i]=np.where(array==i)[0] #Notice change here to take first element
return N
See this answer for more information: What is the purpose of numpy.where returning a tuple?
I think the name of the function is len and not size
objects = (1,2,3)
len(objects)
Will give output as 3
According to the error you posted, Data is of type tuple and there is no attribute shape defined for data. You could try casting Data when you call your preprocess function, e.g.:
preprocess(numpy.array(Data))
.shape is an attribute of numpy ndarrays and tuples don't have such attributes but it's possible to call numpy.shape on a tuple to get its "shape".
import numpy as np
sh = np.shape(Data)
In general (not for OP), it's more useful to get the length of tuples:
len(Data)
In fact, this means you have multiple versions of numpy installed somehow (or there are multiple versions that are overlapping). You need to make sure that numpy is fully uninstalled from your system, then reinstall.
For me, I did
pip uninstall numpy
sudo apt-get purge python3-numpy
Then I had to go to /usr/local/lib/python3.6/dist-packages and delete the numpy folders that were still there for some reason. After that, reinstalling numpy with
pip install numpy
worked. Here is the github issue I opened on it:
https://github.com/numpy/numpy/issues/12775
Had the same issue, fixed by going back to Numpy 1.15.4 Thanks wordsforthewise
working on an assignment and I've been getting this error a lot with the codes our professor is giving us. Here is an example of a code given:
a = np.random.normal(0, 1, 9).reshape(3, 3)
and it returns:
AttributeError Traceback (most recent call last) <ipython-input-10-d5ba530a56da> in <module> ----> 1 a = np.random.normal(0, 1, 9).reshape(3, 3) AttributeError: 'tuple' object has no attribute 'random'
so I'm not sure what I'm doing wrong. Any ideas?
*RESOLVED* thank you u/FunkyDoktor
I am trying to make a discord bot that would turn a message into lowercase. I am encountering an error, as the title suggests, "AttributeError: 'tuple' object has no attribute 'lower'. "
Here is my code if anyone can help.
https://hastebin.com/ibareyilax.py
If this is the wrong subreddit I don't mind taking down my post and posting it elsewhere.
It literally means that the the tuple class in Python doesn't have a method called to. Since you're trying to put your labels onto your device, just do labels = torch.tensor(labels).to(device).
If you don't want to do this, you can change the way the DataLoader works by making it return your labels as a PyTorch tensor rather than a tuple.
Edit
Since the labels seem to be strings, I would convert them to one-hot encoded vectors first:
>>> import torch
>>> labels_unique = set(labels)
>>> keys = {key: value for key, value in zip(labels_unique, range(len(labels_unique)))}
>>> labels_onehot = torch.zeros(size=(len(labels), len(keys)))
>>> for idx, label in enumerate(labels_onehot):
... labels_onehot[idx][keys[label]] = 1
...
>>> labels_onehot = labels.to(device)
I'm shooting a bit in the dark here because I don't know the details exactly, but yeah strings won't work with tensors.
I also got the same error when I was training an Image classification model with a reference-style image dataset. Here I implemented a Custom Dataset Class by extending from torch.utils.data import Dataset class. Same as you I haven't encoded my target labels and they are just a tuple of class names(strings). Since PyTorch tensors don't accept string data directly, I had to convert these labels into integer-encoded tensors before using them in model training.