forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdArray.ARange.cs
More file actions
36 lines (30 loc) · 1.04 KB
/
NdArray.ARange.cs
File metadata and controls
36 lines (30 loc) · 1.04 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace NumSharp.Extensions
{
public static partial class NDArrayExtensions
{
public static NDArray<int> ARange(this NDArray<int> np,int stop, int start = 0, int step = 1)
{
int index = 0;
np.Data = Enumerable.Range(start,stop - start)
.Where(x => index++ % step == 0)
.ToArray();
np.Shape = new Shape(new int[] { stop });
return np;
}
public static NDArray<double> ARange(this NDArray<double> np,int stop, int start = 0, int step = 1)
{
int index = 0;
np.Data = Enumerable.Range(start,stop - start)
.Where(x => index++ % step == 0)
.Select(x => (double)x)
.ToArray();
np.Shape = new Shape(new int[] { stop });
return np;
}
}
}