forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdArray.VStack.cs
More file actions
41 lines (40 loc) · 1.27 KB
/
NdArray.VStack.cs
File metadata and controls
41 lines (40 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NumSharp.Extensions
{
public static partial class NDArrayExtensions
{
/// <summary>
/// Stack arrays in sequence vertically (row wise).
/// </summary>
/// <param name="nps"></param>
/// <returns></returns>
public static NDArray<T> VStack<T>(params NDArray<T>[] nps)
{
if (nps == null || nps.Length == 0)
throw new Exception("Input arrays can not be empty");
List<T> list = new List<T>();
NDArray<T> np = new NDArray<T>();
foreach (NDArray<T> ele in nps)
{
if (nps[0].Shape != ele.Shape)
throw new Exception("Arrays mush have same shapes");
list.AddRange(ele.Data);
}
np.Data = list.ToArray();
if (nps[0].Shape.Length == 1)
{
np.Shape = new Shape(new int[] { nps.Length, nps[0].Shape.Shapes[0] });
}
else
{
int[] shapes = nps[0].Shape.Shapes.ToArray();
shapes[0] *= nps.Length;
np.Shape = new Shape(shapes);
}
return np;
}
}
}