Fonction PyTorch torch.asarray
Manuel de référence PyTorch torch
torch.asarrayest une fonction de PyTorch utilisée pour convertir des données en tableaux de tenseurs.
Définition de fonction
torch.asarray(data, dtype, device)
Exemple d'utilisation
Exemple
import torch
# Convertir à partir d'une liste
x = torch.asarray([1, 2, 3])
print(x)
# Convertir à partir d'un tableau NumPy
import numpy as np
arr = np.array([4, 5, 6])
y = torch.asarray(arr)
print(y)
# Convertir à partir d'une liste
x = torch.asarray([1, 2, 3])
print(x)
# Convertir à partir d'un tableau NumPy
import numpy as np
arr = np.array([4, 5, 6])
y = torch.asarray(arr)
print(y)
Autres extensions