---
source: https://iinventedlight.com/library/notes/pandas-numpy-pytorch.md
title: "DataFrame.to_numpy builds a NumPy array that torch.from_numpy can share"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (pandas-dev/pandas docs); BSD-style (pytorch/pytorch docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: pandas docs, DataFrame.to_numpy, BSD-3-Clause (https://raw.githubusercontent.com/pandas-dev/pandas/main/LICENSE). Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team; Copyright (c) 2011-2026, Open source contributors. PyTorch docs, torch.from_numpy, BSD-style (https://raw.githubusercontent.com/pytorch/pytorch/main/LICENSE)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-16 11:28 PT, Librarian chat widget t55s332: \"Yes, publish all 5 Monday gap notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "No pandas or PyTorch conversion was run for this note; only the fetched documentation was read."
category: coding-references
topic_area: "code-python: pandas NumPy PyTorch interchange"
tags: [pandas, dataframe, numpy, pytorch, tensor, to_numpy, from_numpy]
client: Librarian
sources:
  - id: S1
    title: "pandas.DataFrame.to_numpy"
    publisher: pandas docs
    url: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_numpy.html
    accessed: 2026-11-16
    license: "BSD-3-Clause"
  - id: S2
    title: "torch.from_numpy"
    publisher: PyTorch docs
    url: https://pytorch.org/docs/2.15/generated/torch.from_numpy.html
    accessed: 2026-11-16
    license: "BSD-style"
---
# DataFrame.to_numpy builds a NumPy array that torch.from_numpy can share
**Answer:** Use `DataFrame.to_numpy` to convert a DataFrame to a NumPy array. `torch.from_numpy` creates a Tensor from a `numpy.ndarray`. That tensor can share memory with the array.

## From a DataFrame to NumPy

`DataFrame.to_numpy` converts the DataFrame to a NumPy array. The default dtype is the common NumPy dtype of all types in the DataFrame. Copying data and coercing values may be expensive. The `copy` parameter defaults to False, but `copy=False` does not ensure a no-copy result. Rather, `copy=True` ensure that a copy is made. The return value is a `numpy.ndarray`. `Series.to_numpy` is a similar method for Series.

## From a NumPy array to a tensor

`torch.from_numpy` creates a Tensor from a `numpy.ndarray`. The tensor and the ndarray share memory. A write to the tensor shows up in the array. numpy.float64, numpy.float32, and bool are accepted dtypes. The returned tensor is not resizable. Writing to a tensor created from a read-only NumPy array is unsupported.

## See also

- [pandas-data-structures](https://iinventedlight.com/library/notes/pandas-data-structures/)
- [numpy-broadcasting](https://iinventedlight.com/library/notes/numpy-broadcasting/)
- [hf-safetensors](https://iinventedlight.com/library/notes/hf-safetensors/)
- [numpy-copies-views](https://iinventedlight.com/library/notes/numpy-copies-views/)

## Claims

- id: C1
  claim: DataFrame.to_numpy converts a DataFrame to a NumPy array.
  source: S1
  evidence: "Convert the DataFrame to a NumPy array."

- id: C2
  claim: copy=True forces a copy of the array.
  source: S1
  evidence: "copy=True ensure that a copy is made"

- id: C3
  claim: torch.from_numpy creates a tensor from a NumPy ndarray.
  source: S2
  evidence: "Creates a Tensor from a numpy.ndarray."

- id: C4
  claim: The tensor and ndarray share memory.
  source: S2
  evidence: "The returned tensor and ndarray share the same memory."

## Sources

- [S1] pandas.DataFrame.to_numpy. pandas docs. https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_numpy.html . License: BSD-3-Clause. Accessed 2026-11-16.

- [S2] torch.from_numpy. PyTorch docs. https://pytorch.org/docs/2.15/generated/torch.from_numpy.html . License: BSD-style. Accessed 2026-11-16.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: pandas docs, DataFrame.to_numpy, BSD-3-Clause (https://raw.githubusercontent.com/pandas-dev/pandas/main/LICENSE). Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team; Copyright (c) 2011-2026, Open source contributors. PyTorch docs, torch.from_numpy, BSD-style (https://raw.githubusercontent.com/pytorch/pytorch/main/LICENSE). Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
