I believe you also have to use .detach(). I had to convert my Tensor to a numpy array on Colab which uses CUDA and GPU. I did it like the following:

# this is just my embedding matrix which is a Torch tensor object
embedding = learn.model.u_weight

embedding_list = list(range(0, 64382))

input = torch.cuda.LongTensor(embedding_list)
tensor_array = embedding(input)
# the output of the line below is a numpy array
tensor_array.cpu().detach().numpy()
Answer from azizbro on Stack Overflow
Discussions

RuntimeError: Numpy is not available
Issue description I was running some other code and I faced the error "RuntimeError: Numpy is not available". I searched around and found out that running the code I have attached below p... More on github.com
🌐 github.com
14
May 26, 2022
Tensors vs Numpy Arrays
reach disarm sophisticated strong six coherent cooperative important reminiscent telephone This post was mass deleted and anonymized with Redact More on reddit.com
🌐 r/learnmachinelearning
27
56
April 21, 2023
Torch is being built with the wrong version of NumPy (with pip)
Are you using virtual environments? If not I'd strongly suggest you look at using either Miniconda (a package managing tool for python) or the slightly more manual approach of using venv . That way you can more reliably try different versions of your dependencies to debug this out. Once you do, come back and let us know if you are still seeing these issues and we can dig deeper into the issue. But for now, the potential for cross dependency conflict is too high and could make trouble shooting a real nightmare. More on reddit.com
🌐 r/learnpython
7
9
April 13, 2025
Converting tensors into numpy array and vise versa
i’m working on distilbert for text classification, and want to save the tensors into a data frame so i can use it again as feature generator to illustrate my question more: below are token IDs for one sentence in a row in csv file i’m working on : Token IDs: tensor([ 101, 11113, 2080, 25876, ... More on discuss.pytorch.org
🌐 discuss.pytorch.org
1
0
January 28, 2022
🌐
PyTorch
docs.pytorch.org › intro › learning pytorch with examples › warm-up: numpy
Warm-up: numpy — PyTorch Tutorials 2.11.0+cu130 documentation
July 20, 2022 - import numpy as np import math # Create random input and output data x = np.linspace(-math.pi, math.pi, 2000) y = np.sin(x) # Randomly initialize weights a = np.random.randn() b = np.random.randn() c = np.random.randn() d = np.random.randn() learning_rate = 1e-6 for t in range(2000): # Forward pass: compute predicted y # y = a + b x + c x^2 + d x^3 y_pred = a + b * x + c * x ** 2 + d * x ** 3 # Compute and print loss loss = np.square(y_pred - y).sum() if t % 100 == 99: print(t, loss) # Backprop to compute gradients of a, b, c, d with respect to loss grad_y_pred = 2.0 * (y_pred - y) grad_a = gr
🌐
GitHub
github.com › pytorch › pytorch › issues › 78341
RuntimeError: Numpy is not available · Issue #78341 · pytorch/pytorch
May 26, 2022 - import numpy import torch test_torch = torch.rand(100,1,28,28) print(test_torch.numpy()) PyTorch or Caffe2: Pytorch · How you installed PyTorch (conda, pip, source): pip3 install torch torchvision torchaudio · OS: Windows 11 · PyTorch version: 1.11.0+cpu ·
Published   May 26, 2022
Author   blank-ed
🌐
Quora
quora.com › What-are-the-benefits-of-PyTorch-over-NumPy
What are the benefits of PyTorch over NumPy? - Quora
Answer: PyTorch is a deep learning focused library while NumPy is for scientific computing. Both of these libraries are made with different goals in mind: * If you want to just do basic matrix operations/transformation and array operations then ...
Find elsewhere
🌐
Saturn Cloud
saturncloud.io › blog › converting-from-numpy-array-to-pytorch-tensor-a-comprehensive-guide
Converting from Numpy Array to PyTorch Tensor: A Guide | Saturn Cloud Blog
January 20, 2024 - It’s a staple in the data science community for its efficiency and ease of use. PyTorch, on the other hand, is an open-source machine learning library based on the Torch library.
🌐
Reddit
reddit.com › r/learnpython › torch is being built with the wrong version of numpy (with pip)
r/learnpython on Reddit: Torch is being built with the wrong version of NumPy (with pip)
April 13, 2025 -

Hello, I need help with the problem I'm trying to solve for a few days now. I have to run a project which uses a bunch of packages, including NumPy 1.22 and PyTorch 1.13. I'm using Windows 10 and Python 3.10.11 with pip 23.0.1. When I install the appropriate versions of the packages and try to run the project, I'm getting error: Failed to initialize NumPy: module compiled against API version 0x10 but this version of numpy is 0xf (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:77.). AFAIK 0xf is 1.22 (the version I have installed) and 0x10 is 1.23/1.24.

What I tried:

  1. Reinstalling Python including removing everything Python-related (like files in %APPDATA%) to be sure that no versions of NumPy and PyTorch exist in my system (except for packages bundled in some software that I don't want to uninstall).

  2. Checking the Path variable to be sure that the correct version of Python and pip is used.

  3. Using venv to have a clear environment.

But still somehow torch seems to be installed with NumPy 1.23/1.24 despite the fact that I have no such version of that package in my system (I searched my entire disk). When I import NumPy and print the version and the path, it correctly shows version 1.22 and the path to the package in venv I created.

I also can't update to the newest version of NumPy (or to 1.23/1.24) because then I get incompatibility with SciPy version. I also can't upgrade the project's requirements, the code is from a paper I'm not the author of so it would be cumbersome.

🌐
PyTorch Forums
discuss.pytorch.org › nlp
Converting tensors into numpy array and vise versa - nlp - PyTorch Forums
January 28, 2022 - i’m working on distilbert for text classification, and want to save the tensors into a data frame so i can use it again as feature generator to illustrate my question more: below are token IDs for one sentence in a row in csv file i’m working on : Token IDs: tensor([ 101, 11113, 2080, 25876, 2542, 15009, 11290, 22291, 3370, 2478, 7037, 22160, 3215, 1998, 5760, 5001, 10464, 24895, 15009, 2157, 2002, 17585, 6593, 16940, 1037, 2553, 3189, 1026, 1013, 1055, 1028, 1026, 1013,...
🌐
Kaggle
kaggle.com › code › amirmotefaker › pytorch-vs-numpy
PyTorch vs NumPy | Kaggle
July 14, 2024 - Explore and run AI code with Kaggle Notebooks | Using data from No attached data sources
🌐
NumPy
numpy.org › doc › stable › user › basics.interoperability.html
Interoperability with NumPy — NumPy v2.4 Manual
See the Dask array documentation and the scope of Dask arrays interoperability with NumPy arrays for details. Several Python data science libraries implement the __dlpack__ protocol. Among them are PyTorch and CuPy. A full list of libraries that implement this protocol can be found on this page of DLPack documentation. ... >>> import torch >>> x_torch = torch.arange(5) >>> x_torch tensor([0, 1, 2, 3, 4]) >>> x_np = np.from_dlpack(x_torch) >>> x_np array([0, 1, 2, 3, 4]) >>> # note that x_np is a view of x_torch >>> x_torch[1] = 100 >>> x_torch tensor([ 0, 100, 2, 3, 4]) >>> x_np array([ 0, 100, 2, 3, 4])
🌐
GitHub
github.com › pytorch › pytorch
GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration · GitHub
3 weeks ago - You can write new neural network layers in Python using the torch API or your favorite NumPy-based libraries such as SciPy.
Starred by 99.9K users
Forked by 27.8K users
Languages   Python 63.0% | C++ 29.5% | Cuda 2.7% | C 1.3% | Objective-C++ 1.0% | CMake 0.6%
🌐
Medium
medium.com › @yunjiangster › comparing-speed-of-torch-and-numpy-f22b11aabfcf
Comparing Speed of Torch and Numpy | by Yunjiang Jiang | Medium
June 19, 2023 - Huggingface converts the input to the compute_metrics function from torch tensors to numpy arrays already, since it wasn’t expecting people to do heavy computation within the compute_metrics function.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-pytorch-tensor-to-numpy-array
How to Convert Pytorch tensor to Numpy array? - GeeksforGeeks
June 30, 2021 - Method 1: Using numpy(). ... # importing torch module import torch # import numpy module import numpy # create one dimensional tensor with # float type elements b = torch.tensor([10.12, 20.56, 30.00, 40.3, 50.4]) print(b) # convert this into numpy array using # numpy() method b = b.numpy() # display b
🌐
PyPI
pypi.org › project › pyttsx3
pyttsx3 · PyPI
Text to Speech (TTS) library for Python 3. Works without internet connection or delay. Supports multiple TTS engines, including Sapi5, nsss, and espeak.
      » pip install pyttsx3
    
Published   Jul 08, 2025
Version   2.99
🌐
Hugging Face
huggingface.co › docs › safetensors › index
Safetensors · Hugging Face
import torch from safetensors.torch import save_file tensors = { "embedding": torch.zeros((2, 2)), "attention": torch.zeros((2, 3)) } save_file(tensors, "model.safetensors")
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.5 documentation
February 27, 2026 - These read-only attributes are set to the argument values (or their default). They have no other explicit functionality; however, they are used by NumPy and other third-party packages.