Search notes:

Convert numpy arrays to torch tensor

The following snippet converts a list of numpy arrays to torch tensors.
import numpy
import torch

data_np    = [
              numpy.array([
                     [1.1, 2.1, 3.2],
                     [4.2, 5.8, 6.9]
                  ]),
              numpy.array([
                     [ 7.2,  8.0],
                     [ 9.1, 10.1],
                     [11.7, 12.6]
                 ])
             ]


data_torch = list(map(torch.tensor, data_np ))

print(data_torch)

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758203004, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/libraries/torch/misc/convert-numpy-array-to-torch-tensor(52): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78