1import tensorflow as tf
2
3a = tf.constant([[1, 2], [3, 4]])
4b = tf.add(a, 1)
5
6a.numpy()
7# array([[1, 2],
8# [3, 4]], dtype=int32)
9
10b.numpy()
11# array([[2, 3],
12# [4, 5]], dtype=int32)
13
14tf.multiply(a, b).numpy()
15# array([[ 2, 6],
16# [12, 20]], dtype=int32)
17
1import torch
2
3# Create PyTorch tensor
4A_torch = torch.tensor([1, 2])
5
6# Convert tensor to NumPy array
7A_np = A_torch.numpy()
1import numpy as np
2import torch
3
4numpy_array = np.array([1,3,5])
5tensor_array = torch.from_numpy(numpy_array)