forked from SciSharp/Numpy.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumPy.linalg.norm.cs
More file actions
108 lines (100 loc) · 4.08 KB
/
NumPy.linalg.norm.cs
File metadata and controls
108 lines (100 loc) · 4.08 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Numpy;
using Numpy.Models;
using Python.Runtime;
namespace Numpy
{
/// <summary>
/// Manual type conversions
/// </summary>
public partial class NumPy
{
/// <summary>
/// Matrix or vector norm.
///
/// This function is able to return one of eight different matrix norms,
/// or one of an infinite number of vector norms (described below), depending
/// on the value of the ord parameter.
///
/// Notes
///
/// For values of ord <= 0, the result is, strictly speaking, not a
/// mathematical ‘norm’, but it may still be useful for various numerical
/// purposes.
///
/// The following norms can be calculated:
///
/// The Frobenius norm is given by [1]:
///
/// The nuclear norm is the sum of the singular values.
///
/// References
/// </summary>
/// <param name="x">
/// Input array. If axis is None, x must be 1-D or 2-D.
/// </param>
/// <param name="ord">
/// Order of the norm (see table under Notes). inf means numpy’s
/// inf object.
/// </param>
/// <param name="axis">
/// If axis is an integer, it specifies the axis of x along which to
/// compute the vector norms. If axis is a 2-tuple, it specifies the
/// axes that hold 2-D matrices, and the matrix norms of these matrices
/// are computed. If axis is None then either a vector norm (when x
/// is 1-D) or a matrix norm (when x is 2-D) is returned.
/// </param>
/// <param name="keepdims">
/// If this is set to True, the axes which are normed over are left in the
/// result as dimensions with size one. With this option the result will
/// broadcast correctly against the original x.
/// </param>
/// <returns>
/// Norm of the matrix or vector(s).
/// </returns>
public NDarray norm(NDarray x, int? ord = null, int[] axis = null, bool? keepdims = null)
{
var pyargs = ToTuple(new object[] { x, });
var kwargs = new PyDict();
if (ord != null) kwargs["ord"] = ToPython(ord);
if (axis != null) kwargs["axis"] = ToPython(axis);
if (keepdims != null) kwargs["keepdims"] = ToPython(keepdims);
var linalg = self.GetAttr("linalg");
dynamic py = linalg.InvokeMethod("norm", pyargs, kwargs);
return ToCsharp <NDarray> (py);
}
public float norm(NDarray x, int? ord = null)
{
var pyargs = ToTuple(new object[] { x, });
var kwargs = new PyDict();
if (ord != null) kwargs["ord"] = ToPython(ord);
var linalg = self.GetAttr("linalg");
dynamic py = linalg.InvokeMethod("norm", pyargs, kwargs);
return ToCsharp<float>(py);
}
public float norm(NDarray x, string ord)
{
var pyargs = ToTuple(new object[] { x, });
var kwargs = new PyDict();
if (ord != null) kwargs["ord"] = ToPython(ord);
var linalg = self.GetAttr("linalg");
dynamic py = linalg.InvokeMethod("norm", pyargs, kwargs);
return ToCsharp<float>(py);
}
public float norm(NDarray x, Constants ord)
{
if (ord!=Constants.inf && ord!=Constants.neg_inf)
throw new ArgumentException("ord must be either inf or neg_inf");
var pyargs = ToTuple(new object[] { x, });
var kwargs = new PyDict();
if (ord != null) kwargs["ord"] = ord==Constants.inf ? self.inf : -(self.inf);
var linalg = self.GetAttr("linalg");
dynamic py = linalg.InvokeMethod("norm", pyargs, kwargs);
return ToCsharp<float>(py);
}
}
}