in prediction = net(X_train), X_train is a numpy array, but torch expects a tensor.

You need to convert to torch tensor, and move to gpu if you want

the 1st line should be

X_train = torch.from_numpy(df.drop('class', axis=1).to_numpy())
Answer from Gulzar on Stack Overflow
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-numpy-ndarray-object-has-no-attribute-dim › 16026
AttributeError: 'numpy.ndarray' object has no attribute 'dim' - PyTorch Forums
April 5, 2018 - Hello Team, i am new to the forum and to Pytorch, i want to predict 3 real values Y1, Y2 & Y3 from input values X1, X2…X10 using the below model, but i get the error in title: File “/home/abdelmoula/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py”, line 833, in linear if input.dim() == 2 and bias is not None: AttributeError: ‘numpy.ndarray’ object has no attribute ‘dim’ Can you please on what is wrong ? thank you ######################## MODEL: import pandas as pd import to...
Discussions

'numpy.ndarray' object has no attribute 'dim'
Hi, when I try to run the program with test mode, the error occurs. It shows 'numpy.ndarray' object has no attribute 'dim'. The error is located at solver.py, line 376, "edges_... More on github.com
🌐 github.com
1
October 30, 2020
AttributeError: 'numpy.ndarray' object has no attribute 'dim' from torch/nn/functional.py
Based on answer here https://discuss.pytorch.org/t/attributeerror-numpy-ndarray-object-has-no-attribute-dim/16026/2, I tried using Variable(), however, the args are Tensors already and I get the TypeError: expected np.ndarray (got Tensor) error. Code def forward(self, state): """ Build the ... More on discuss.pytorch.org
🌐 discuss.pytorch.org
0
0
January 10, 2020
Iris example - AttributeError: 'numpy.ndarray' object has no attribute 'dim'
I am running a simple CNN for a classification task. There is something is wrong with the way I am reading the array data as a tensor. I am running into this error AttributeError: 'numpy.ndarray' object has no attribute 'dim. Any suggestions? import pandas as pd from sklearn.model_selection ... More on discuss.pytorch.org
🌐 discuss.pytorch.org
1
0
October 2, 2020
python - AttributeError: 'numpy.ndarray' object has no attribute 'dim' with pytorch and scipy.optimize minimize - Stack Overflow
6 Python - AttributeError: 'numpy.ndarray' object has no attribute 'to' More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › pytorch › pytorch › issues › 41657
AttributeError: 'numpy.ndarray' object has no attribute 'dim' · Issue #41657 · pytorch/pytorch
July 19, 2020 - AttributeError: 'numpy.ndarray' object has no attribute 'dim'#41657 · Copy link · veds12 · opened · on Jul 19, 2020 · Issue body actions · I am trying to implement a deep Q network using pytorch.
Author   veds12
🌐
GitHub
github.com › yongqyu › MolGAN-pytorch › issues › 8
'numpy.ndarray' object has no attribute 'dim' · Issue #8 · yongqyu/MolGAN-pytorch
October 30, 2020 - Hi, when I try to run the program with test mode, the error occurs. It shows 'numpy.ndarray' object has no attribute 'dim'. The error is located at solver.py, line 376, "edges_...
Author   kulasimu
🌐
PyTorch Forums
discuss.pytorch.org › reinforcement-learning
AttributeError: 'numpy.ndarray' object has no attribute 'dim' from torch/nn/functional.py - reinforcement-learning - PyTorch Forums
January 10, 2020 - I’m working on a DDPG implementation and getting AttributeError: 'numpy.ndarray' object has no attribute 'dim' from my Actor class. Based on answer here https://discuss.pytorch.org/t/attributeerror-numpy-ndarray-object-has-no-attribute-dim/16026/2, I tried using Variable(), however, the args are Tensors already and I get the TypeError: expected np.ndarray (got Tensor) error.
🌐
Stack Overflow
stackoverflow.com › questions › 63164627 › attributeerror-numpy-ndarray-object-has-no-attribute-dim-with-pytorch-and-s
python - AttributeError: 'numpy.ndarray' object has no attribute 'dim' with pytorch and scipy.optimize minimize - Stack Overflow
2 scipy.optimize.minimize returning zero-dimensional array? 2 'numpy.ndarray' object is not callable error with optimize.minimize · 23 TypeError: can't convert np.ndarray of type numpy.object_ 9 Python Neural Network: 'numpy.ndarray' object has no attribute 'dim'
🌐
Stack Overflow
stackoverflow.com › questions › 74551169 › getting-attributeerror-numpy-ndarray-object-has-no-attribute-dim-when-conve
python - getting AttributeError: 'numpy.ndarray' object has no attribute 'dim' when converting tensorflow code to pytorch - Stack Overflow
16 IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number · 9 Python Neural Network: 'numpy.ndarray' object has no attribute 'dim'
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › error creating numpy v-stack, 'attributeerror: 'numpy.ndarray' object has no attribute 'np'
r/learnpython on Reddit: Error creating numpy v-stack, 'AttributeError: 'numpy.ndarray' object has no attribute 'np'
May 4, 2021 -

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

🌐
Stack Overflow
stackoverflow.com › questions › 62801695 › attributeerror-numpy-ndarray-object-has-no-attribute-dim
machine learning - AttributeError: 'numpy.ndarray' object has no attribute 'dim' - Stack Overflow
July 8, 2020 - class Net(nn.Module): def __init__(self, input_dim=10): super().__init__() self.fc1 = nn.Linear(input_dim, int(0.75 * input_dim)) self.fc2 = nn.Linear(int(0.75 * input_dim), int(0.5 * input_dim)) self.fc3 = nn.Linear(int(0.5 * input_dim), int(0.33 * input_dim)) self.fc4 = nn.Linear(int(0.33 * input_dim), int(0.25 * input_dim)) self.fc5 = nn.Linear(int(0.25 * input_dim), int(0.33 * input_dim)) self.fc6 = nn.Linear(int(0.33 * input_dim), int(0.5 * input_dim)) self.fc7 = nn.Linear(int(0.5 * input_dim), int(0.75 * input_dim)) self.fc8 = nn.Linear(int(0.75 * input_dim), input_dim) def forward(self,
🌐
Stack Overflow
stackoverflow.com › questions › 58439394 › size-mismatch-m1-1-x-5-m2-7-x-100-at-pytorch-aten-src-th-generic-thtens
deep learning - Size mismatch, m1: [1 x 5], m2: [7 x 100] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:752 - Stack Overflow
October 18, 2019 - Well, your input_dim should be len(X_train) instead of len(x). ... That's great. It solved my error. But now I ot the another one. "AttributeError: 'numpy.ndarray' object has no attribute 'dim'"
🌐
Fast.ai
forums.fast.ai › part 1 (2018) › beginner (2018)
Self.u(users) - Beginner (2018) - fast.ai Course Forums
January 22, 2018 - What is self.u(users) from Lecture 5 (1h 05min)? If self.u is Embedding it should be a matrix of weights, not a function. Trying the following code: def get_emb(ni,nf): e = nn.Embedding(ni, nf) e.weight.data.uniform_(-0.01,0.01) return e items = cf.items users = cf.users (u, m) = [get_emb(*o) for o in [(len(users), n_factors), (len(items), n_factors)]] type(u) returns torch.nn.modules.sparse.Embedding then testing with u(users) throws an error --------------------------------...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-numpy-ndarray-object-has-no-attribute-index
How to Fix: ‘numpy.ndarray’ object has no attribute ‘index’ - GeeksforGeeks
November 28, 2021 - This error arises because numpy's float attribute has been deprecated and removed in favor of using standard Python types. In this article, we will learn how to fix "AttributeError: m ... When working with NumPy we might encounter the error ...
🌐
Quora
quora.com › Why-do-I-get-numpy-ndarray-object-has-no-attribute-append-error
Why do I get “numpy.ndarray object has no attribute append error”? - Quora
For the same reason, each level of a multidimensional array will contain the same number of lower-dimensional arrays. ... This array contains 2 arrays of 3 arrays of 5 integers. In NumPy, we call its shape (2, 3, 5). The shape of an array is fixed. ... [3] ndarrays cannot change in size and shape. (You can, however, change values inside an ndarray, provided the replacements are of the same type.) In Python, an attribute is anything that follows a dot after the object, which include data attributes (arr.shape) or methods (arr.flatten()).
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-numpy-ndarray-object-has-no-attribute-append
How to Fix: ‘numpy.ndarray’ object has no attribute ‘append’ - GeeksforGeeks
November 28, 2021 - As in the output, we can see that initially, the NumPy array had 4 items (1, 2, 3, 4). After appending 5 to the list, it is reflected in the NumPy array. This is so because here the append function is used on NumPy and not on NumPy array object (numpy.ndarray).