Learn Before
Tensor to NumPy Array Conversion
Converting a deep learning tensor to a NumPy array (ndarray), or vice versa, is straightforward but involves framework-specific memory management behaviors. In PyTorch, the converted objects share the same underlying memory (e.g., via X.numpy() and torch.from_numpy()), meaning an in-place modification to one affects the other. Conversely, in frameworks like TensorFlow (via X.numpy() and tf.constant()), MXNet (via X.asnumpy() and np.array()), and JAX (via jax.device_get() and jax.device_put()), the converted result does not share memory. This isolation prevents the CPU or GPU from halting computations while waiting for Python's NumPy package to interact with the shared memory chunk.
0
1
Tags
D2L
Dive into Deep Learning @ D2L
Related
Vector (1D Tensor)
Tensor Indexing
Tensor to NumPy Array Conversion
Size-1 Tensor to Python Scalar Conversion
jax.numpy.array()
Typographical Conventions for General Tensors
Single Image Representation as a 3rd-Order Tensor
Programmatic Construction of Higher-Order Tensors
Tensor-Scalar Arithmetic
Tensor Concatenation
Elementwise Tensor Operation
Tensor Element Summation
Tensor Class Interface Summary
Vector
Tensor Initialization with Zeros
Tensor Initialization with Ones
Evenly Spaced Tensor Initialization
Random Tensor Initialization
Programmatic Construction of Tensors from Nested Lists
Tensor as a Software Object
Tensor Decomposition
NumPy ndarray attributes
NumPy Multiplication
Broadcasting in array computations
Tensor to NumPy Array Conversion