How to append tensors into a list using loops

I have the following code which outputs 2 arrays in a list:

arr1 = np.array([[1.,2,3], [4,5,6], [7,8,9]])

arr_split = np.array_split(arr1,
                           indices_or_sections = 2,
                           axis = 0)

arr_split

Output:

[array([[1., 2., 3.],
        [4., 5., 6.]]), array([[7., 8., 9.]])]

How do I cast these 2 arrays into PyTorch tensors and put them into a list using for (or while) loops, so that they look like this:

[tensor([[1., 2., 3.],
         [4., 5., 6.]], dtype=torch.float64)
tensor([[7., 8., 9.]], dtype=torch.float64)]

Many thanks in advance!

torch_arr = [torch.from_numpy(x) for x in arr_split]
1 Like

Many thanks for this