Class py
Implements Python utility functions that are often used in connection with numpy
public static class py
- Inheritance
-
py
- Inherited Members
Methods
complex(string)
CPython 3.12's complex(str): parses one Python complex literal into a Complex, with the
grammar NumPy uses for a str → complex128 conversion (np.array(['1+2j']).astype(complex)).
public static Complex complex(string input)
Parameters
inputstringThe text:
'10+5j','3-2j','4j','j','5','1e3','inf'/'nan'in any case,'(1+2j)', eitherjorJ, surrounding whitespace, underscores between digits, non-ASCII decimal digits.
Returns
- Complex
The complex value.
Remarks
This replaced a culture-dependent regular expression (double.Parse in the CURRENT culture, so under
de-DE '1.5' read 15) that refused '1e3', 'inf', '(1+2j)', whitespace and
underscores, accepted '1+', and threw FormatException. The parser is the one every
NumSharp text → complex route runs (ToComplex(string), astype, setitem), so the
answers agree.
Exceptions
- ArgumentNullException
inputis null.- ValueError
The text is not a complex literal (CPython's text:
complex() arg is a malformed string) — the empty string and whitespace included.
range(int)
public static int[] range(int n)
Parameters
nint
Returns
- int[]