forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdArray.Normalize.cs
More file actions
34 lines (32 loc) · 967 Bytes
/
NdArray.Normalize.cs
File metadata and controls
34 lines (32 loc) · 967 Bytes
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
using System;
namespace NumSharp
{
public partial class NDArray
{
/// <summary>
/// Normalizes all entries into the range between 0 and 1
///
/// Note: this is not a numpy function.
/// </summary>
public void Normalize()
{
var min = this.min(0);
var max = this.max(0);
if (ndim == 2)
{
for (int col = 0; col < shape[1]; col++)
{
double der = max.Storage.GetValue<double>(col) - min.Storage.GetValue<double>(col);
for (int row = 0; row < shape[0]; row++)
{
this[row, col] = (NDArray) (Storage.GetValue<double>(row, col) - min.Storage.GetValue<double>(col)) / der;
}
}
}
else
{
throw new NotImplementedException();
}
}
}
}