forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNDArray.Slicing.cs
More file actions
47 lines (42 loc) · 1.29 KB
/
NDArray.Slicing.cs
File metadata and controls
47 lines (42 loc) · 1.29 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
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Text;
namespace NumSharp.Core
{
public partial class NDArray<T>
{
public NDArray<NDArray<T>> this[Slice select]
{
get
{
var result = new NDArray<NDArray<T>>();
result.Data = new NDArray<T>[select.Length];
result.shape = new Shape(select.Length);
int[] shape = new int[Shape.Length];
for (int i = 0; i < Shape.Length; i++)
{
if (i == 0)
{
shape[i] = select.Step;
}
else
{
shape[i] = Shape[i];
}
}
int index = 0;
var list = new NDArray<T>();
for (int s = select.Start; s< select.Stop; s+= select.Step)
{
var n = new NDArray<T>();
Span<T> data = Data;
n.Data = data.Slice(s, select.Step).ToArray();
n.Shape = new Shape(shape);
result.Data[index] = n;
index++;
}
return result;
}
}
}
}