diff --git a/src/TensorFlowNET.Core/APIs/tf.array.cs b/src/TensorFlowNET.Core/APIs/tf.array.cs index df8e69c3..99856a59 100644 --- a/src/TensorFlowNET.Core/APIs/tf.array.cs +++ b/src/TensorFlowNET.Core/APIs/tf.array.cs @@ -140,6 +140,16 @@ namespace Tensorflow public Tensor shape(Tensor input, string name = null, TF_DataType out_type = TF_DataType.TF_INT32) => array_ops.shape_internal(input, name, optimize: true, out_type: out_type); + /// + /// Stacks a list of rank-`R` tensors into one rank-`(R+1)` tensor. + /// + /// + /// + /// + /// A stacked `Tensor` with the same type as `values`. + public Tensor stack(Tensor[] values, int axis = 0, string name = "stack") + => array_ops.stack(values, axis: axis, name: name); + /// /// Unpacks the given dimension of a rank-`R` tensor into rank-`(R-1)` tensors. /// diff --git a/src/TensorFlowNET.Core/Operations/array_ops.py.cs b/src/TensorFlowNET.Core/Operations/array_ops.py.cs index c52e2821..5e82f50e 100644 --- a/src/TensorFlowNET.Core/Operations/array_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/array_ops.py.cs @@ -308,6 +308,18 @@ namespace Tensorflow public static (Tensor, Tensor) unique(Tensor x, TF_DataType out_idx = TF_DataType.TF_INT32, string name = null) => gen_array_ops.unique(x, out_idx: out_idx, name: name); + public static Tensor stack(Tensor[] values, int axis = 0, string name = "stack") + { + if (axis == 0) + { + return ops.convert_to_tensor(values, name: name); + } + + var value_shape = ops.convert_to_tensor(values[0], name: name).TensorShape; + + return gen_array_ops.pack(values, axis: axis, name: name); + } + public static Tensor[] unstack(Tensor value, int? num = null, int axis = 0, string name = "unstack") { if(num == null)