This is a known error, you need to uninstall numpy by:

pip uninstall numpy

then install "numpy<1.26.4" afresh.

pip install "numpy<1.26.4"

References:

https://github.com/huggingface/diffusers/issues/9069#issuecomment-2267596351

https://github.com/pytorch/pytorch/issues/135836#issuecomment-2347209235

Answer from Talha Tayyab on Stack Overflow
🌐
GitHub
github.com › pytorch › pytorch › issues › 135836
TypeError: expected np.ndarray (got numpy.ndarray) · Issue #135836 · pytorch/pytorch
September 12, 2024 - 🐛 Describe the bug Bug When I try to convert a numpy to torch tensor, I got the error TypeError: expected np.ndarray (got numpy.ndarray) How to reproduce import numpy as np import torch import torch.nn as nn x = np.array([[1, 2, 3, 4], [...
Author   yzhao30
Discussions

np.ndArray in tensor - Beginner (2018)
Hi everyone, I am trying to run Resnet18 on STL_10, but get the following error message: RuntimeError: can’t convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8. On the face of it, my arrays look ok shape-wise ... More on forums.fast.ai
🌐 forums.fast.ai
0
November 28, 2017
Why do I get "TypeError: expected np.ndarray (got numpy.ndarray)" when I use torch.from_numpy() function?
Why do I get “TypeError: expected np.ndarray (got numpy.ndarray)” when I use torch.from_numpy() function? Isn’t np.ndarray equivalent to numpy.ndarray? Also, there doesn’t seem to be any np.ndarray type, but only numpy.ndarray type. Traceback (most recent call last): File "test_opencv.py", ... More on discuss.pytorch.org
🌐 discuss.pytorch.org
14
0
February 18, 2019
python - expected np.ndarray (got DataFrame) - Stack Overflow
I wanted to find out the output_size of a convolution operation, but I am strugglin with converting my dataframe into a tensor. output_size = torch.nn.Conv2d(3, 5, 5,stride=1, padding=3, ... More on stackoverflow.com
🌐 stackoverflow.com
python - how to convert series numpy array into tensors using pytorch - Stack Overflow
I am trying to convert image labels convert into tensor, but I got some error please help me to convert to tensor: Here My code: features_train, features_test, targets_train, targets_test = More on stackoverflow.com
🌐 stackoverflow.com
🌐
Fast.ai
forums.fast.ai › part 1 (2018) › beginner (2018)
np.ndArray in tensor - Beginner (2018)
November 28, 2017 - Hi everyone, I am trying to run Resnet18 on STL_10, but get the following error message: RuntimeError: can’t convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8.
🌐
GitHub
github.com › nlsde-safety-team › DualAttentionAttack › issues › 12
TypeError: expected np.ndarray (got Tensor) · Issue #12 · nlsde-safety-team/DualAttentionAttack
Try changing the code to look like this: texture_origin = torch.Tensor(textures[None, :, :, :, :, :].cpu()).cuda(device=0)
Find elsewhere
🌐
Ray
discuss.ray.io › rllib
Offline tutorial : TypeError: must be Tensor, not numpy.ndarray - RLlib - Ray
February 11, 2025 - How severe does this issue affect your experience of using Ray? High: It blocks me to complete my task. Hello, following the tutorial for offline data : Working with offline data — Ray 2.42.0 I’m stuck at training where the input is not cast to tensor type.
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › robotics & edge computing › jetson systems › jetson orin nx
TypeError: expected np.ndarray (got numpy.ndarray) - Jetson Orin NX - NVIDIA Developer Forums
July 1, 2024 - I am unable to run the python script the following error throwing when i try run the file: Traceback (most recent call last): File “/home/ubuntu/Downloads/SiamTrackers-master/NanoTrack/bin/demo.py”, line 143, in main() File “/home/ubuntu/Downloads/SiamTrackers-master/NanoTrack/bin/demo.py”, ...
🌐
Netlify
kirankamath.netlify.app › blog › five-pytorch-functions-i-found-useful
Five PyTorch functions I like | Kiran U Kamath
the need of this funtion is to convert from numpy nd array to tensor · # Example 3 - breaking (to illustrate when it breaks) g = [7,7,7] h = torch.from_numpy(g) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-22-f48bcc71eb26> in <module> 1 # Example 3 - breaking (to illustrate when it breaks) 2 g = [7,7,7] ----> 3 h = torch.from_numpy(g) TypeError: expected np.ndarray (got list) given anything else then ndarray this function throws error.
🌐
GeeksforGeeks
geeksforgeeks.org › python-pytorch-from_numpy
Python PyTorch from_numpy() | GeeksforGeeks
April 22, 2020 - PyTorch is an open-source machine learning library developed by Facebook. It is used for deep neural network and natural language processing purposes. The function torch.from_numpy() provides support for the conversion of a numpy array into a tensor in PyTorch. It expects the input as a numpy array (numpy.ndarray).
🌐
Hugging Face
huggingface.co › spaces › openai › whisper › discussions › 69
openai/whisper · New version
TypeError: conv1d() received an invalid combination of arguments - got (numpy.ndarray, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of: (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups) didn't match because some of the arguments have invalid types: (!numpy.ndarray!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-cant-assign-a-numpyndarray-to-a-torchfloattensor
How to Fix "Can't Assign a numpy.ndarray to a torch.FloatTensor"? - GeeksforGeeks
July 23, 2025 - The error "Can't assign a numpy.ndarray to a torch.FloatTensor" occurs when you attempt to assign a NumPy array to a PyTorch tensor directly, which is not allowed. PyTorch and NumPy are different libraries with different data structures, so ...
🌐
Terra Incognita
blog.christianperone.com › home › python
Python | Terra Incognita
at::Tensor tensor_from_numpy(PyObject* obj) { if (!PyArray_Check(obj)) { throw TypeError("expected np.ndarray (got %s)", Py_TYPE(obj)->tp_name); } auto array = (PyArrayObject*)obj; int ndim = PyArray_NDIM(array); auto sizes = to_aten_shape(ndim, PyArray_DIMS(array)); auto strides = to_aten_shape(ndim, PyArray_STRIDES(array)); // NumPy strides use bytes.
🌐
Readthedocs
tensorcircuit.readthedocs.io › en › latest › _modules › tensornetwork › backends › jax › jax_backend.html
tensornetwork.backends.jax.jax_backend - TensorCircuit Documentation
[docs] def sqrt(self, tensor: Tensor) -> Tensor: return jnp.sqrt(tensor) def convert_to_tensor(self, tensor: Tensor) -> Tensor: if (not isinstance(tensor, (np.ndarray, jnp.ndarray)) and not jnp.isscalar(tensor)): raise TypeError(("Expected a `jnp.array`, `np.array` or scalar. " f"Got {type(tensor)}")) result = jnp.asarray(tensor) return result ·
🌐
PyTorch Forums
discuss.pytorch.org › t › converting-my-np-ndarray-input-and-mask-to-tensor-but-got-an-error › 103309
Converting my np.ndarray input and mask to tensor but got an error - PyTorch Forums
November 18, 2020 - Hi! I am trying to convert my input images and its masks to tensor from numpy.ndarray but I encountered an error along the way. for img in train_gen: img = torch.from_numpy(img) print(img)
🌐
Chsasank
chsasank.com › vision › _modules › torchvision › transforms.html
torchvision.transforms — Torchvision master documentation
""" if not(_is_numpy_image(pic) or _is_tensor_image(pic)): raise TypeError('pic should be Tensor or ndarray. Got {}.'.format(type(pic))) npimg = pic mode = None if isinstance(pic, torch.FloatTensor): pic = pic.mul(255).byte() if torch.is_tensor(pic): npimg = np.transpose(pic.numpy(), (1, 2, 0)) assert isinstance(npimg, np.ndarray) if npimg.shape[2] == 1: npimg = npimg[:, :, 0] if npimg.dtype == np.uint8: mode = 'L' if npimg.dtype == np.int16: mode = 'I;16' if npimg.dtype == np.int32: mode = 'I' elif npimg.dtype == np.float32: mode = 'F' elif npimg.shape[2] == 4: if npimg.dtype == np.uint8: mode = 'RGBA' else: if npimg.dtype == np.uint8: mode = 'RGB' assert mode is not None, '{} is not supported'.format(npimg.dtype) return Image.fromarray(npimg, mode=mode) def normalize(tensor, mean, std): """Normalize a tensor image with mean and standard deviation.
🌐
GitHub
github.com › atnlp › torchtext-summary › issues › 3
TypeError: expected np.ndarray (got numpy.ndarray) · Issue #3 · atnlp/torchtext-summary
August 7, 2019 - weight[index, :] = torch.from_numpy(wvmodel.get_vector(idx_to_word[word_to_idx[wvmodel.index2word[i]]])) 高版本会报错(如101版) TypeError: expected np.ndarray (got numpy.ndarray) 将torch.from_numpy()改为torch.Tensor()即可 建议注明
Author   BoKaiSun
🌐
PyTorch Forums
discuss.pytorch.org › t › cant-convert-a-given-np-ndarray-to-a-tensor › 21321
Can't convert a given np.ndarray to a tensor - PyTorch Forums
July 18, 2018 - RuntimeError: can't convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8 · Can you print the type of your data? you might have to cast it as a one of the accepted types before you convert · Seeing floats doesn’t ...