I am quite new with programming, and more specifically with python, but I am working with very complex (and huge) simulation scripts. My problem is: I have some tensors (i.e., 3D matrix), and I want to stack them. Like: Each tensor has a size of (16128,3,4) (type float64), as I have 4 of these tensors, I want an output with a size of (16128,3,16). anybody knows how to do it? Thank you in advance.
Asked
Active
Viewed 364 times
1 Answers
0
Use np.concatenate()
in numpy
:
import numpy as np
tensors = [np.random.normal(0, 1, (16128,3,4)) for _ in range(4)]
result = np.concatenate(tensors, axis=-1)
result.shape # (16128, 3, 16)
OR tf.concat
in tensorflow
:
import tensorflow as tf
tensors = [tf.random.normal(shape=(16128,3,4)) for _ in range(4)]
result = tf.concat(tensors, axis=-1)
result.get_shape().as_list() # [16128, 3, 16]

Vlad
- 8,225
- 5
- 33
- 45