np.split
martindevans opened this issue · 12 comments
np.split accepts an integer or an array.
indices_or_sections : int or 1-D array
It behaves quite differently depending on which is used.
However, in this wrapper it only accepts an int[]
.
public NDarray[] split(int[] indices_or_sections, int? axis = 0)
I'll add the overload for you
this test proves it works now:
[TestMethod]
public async Task IssueByMartinDevans()
{
//>>> x = np.arange(9)
//>>> np.split(x, 3)
//[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8])]
var x = np.arange(9);
var b = np.split(x, 3).repr();
var a = "(array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8]))";
Assert.AreEqual(a, b);
//>>> x = np.arange(8.0)
//>>> np.split(x, [3, 5, 6, 10])
//[array([0., 1., 2.]),
//array([3., 4.]),
//array([5.]),
//array([6., 7.]),
//array([], dtype = float64)]
x = np.arange(8);
b = np.split(x, new[] { 3, 5, 6, 10 }).repr();
a = "(array([0, 1, 2]), array([3, 4]), array([5]), array([6, 7]), array([], dtype=int32))";
Assert.AreEqual(a, b);
}
Update on Nuget: https://www.nuget.org/packages/Numpy/3.11.1.32
Wow! Thanks for the incredibly fast fix, very much appreciated ❤️
Unfortunately calling x.split(3, axis:-1)
caused this error:
Python.Runtime.PythonException: ''numpy.ndarray' object has no attribute 'split''
Using np.split(x, 3, axis: -1);
is fine though.
Unfortunately calling
x.split(3, axis:-1)
caused this error:Python.Runtime.PythonException: ''numpy.ndarray' object has no attribute 'split''
Can you show the code how you come by that x
which you call split
on ?
Even something as simple as this triggers it for me:
NDarray x = np.array(new[] { 1, 2, 3 });
x.split(3, axis: -1);
While working with other things I noticed this causes a similar error:
NDarray x = np.array(new[] { 1, 2, 3 });
x.matmul(x);
Python.Runtime.PythonException: ''numpy.ndarray' object has no attribute 'matmul''
So this may be a broader issue of NDarray.whatever methods vs np.whatever helpers?
I don't know if it's relevant, but I do have this somewhat cryptic message in the log:
Could not find platform dependent libraries <exec_prefix>
So this may be a broader issue of NDarray.whatever methods vs np.whatever helpers?
Yes, you are right, if you look here, not all methods are defined on NDArray: https://numpy.org/doc/stable/reference/arrays.ndarray.html#array-methods
I obviously made a wrong assumption here by generating all methods as static functions of np
as well as members of NDarray
. Looks like the members should only be generated for the supported ones.
I'll remove split
and matmul
members and for all others that should not be there I leave it up to users to find out and remove on demand when reported. It is kinda dangerous to remove all which are not listed on that page, maybe some do work and are not documented. Who knows.
Is it worth generating all of the np.whatever methods as static extension methods? That way you get member-like calls for free.
yes, that is also a good idea
You can try it in https://www.nuget.org/packages/Numpy/3.11.1.33 once it is online.