Comments (5)
you are of course right and I changed that. the change will go into the next release
from numpy.net.
Right, directly editing the generated code is not the right way. The change has to be made in the generator which is located in the CodeMinion project. It is probably very easy to fix. I am taking a look ...
from numpy.net.
This unit test works now
[TestMethod]
public void take_along_axisTest()
{
// For this sample array
// >>> a = np.array([[10, 30, 20], [60, 40, 50]])
var a= np.array(new[,]{{10, 30, 20}, {60, 40, 50}});
// We can sort either by using sort directly, or argsort and this function
// >>> np.sort(a, axis=1)
// array([[10, 20, 30],
// [40, 50, 60]])
// >>> ai = np.argsort(a, axis=1); ai
// array([[0, 2, 1],
// [1, 2, 0]], dtype=int64)
// >>> np.take_along_axis(a, ai, axis=1)
// array([[10, 20, 30],
// [40, 50, 60]])
//
var given= np.sort(a, axis: 1);
var expected=
"array([[10, 20, 30],\n" +
" [40, 50, 60]])";
Assert.AreEqual(expected, given.repr);
var ai = np.argsort(a, axis: 1);
given = ai;
expected=
"array([[0, 2, 1],\n" +
" [1, 2, 0]], dtype=int64)";
Assert.AreEqual(expected, given.repr);
given= np.take_along_axis(a, ai, axis: 1);
expected=
"array([[10, 20, 30],\n" +
" [40, 50, 60]])";
Assert.AreEqual(expected, given.repr);
// The same works for max and min, if you expand the dimensions:
// >>> np.expand_dims(np.max(a, axis=1), axis=1)
// array([[30],
// [60]])
// >>> ai = np.expand_dims(np.argmax(a, axis=1), axis=1)
// >>> ai
// array([[1],
// [0], dtype=int64)
// >>> np.take_along_axis(a, ai, axis=1)
// array([[30],
// [60]])
//
given= np.expand_dims(np.max(a, axis:new int[]{1}), axis:1);
expected=
"array([[30],\n" +
" [60]])";
Assert.AreEqual(expected, given.repr);
given= ai = np.expand_dims(np.argmax(a, axis:1), axis:1);
given= ai;
expected=
"array([[1],\n" +
" [0]], dtype=int64)";
Assert.AreEqual(expected, given.repr);
given= np.take_along_axis(a, ai, axis:1);
expected=
"array([[30],\n" +
" [60]])";
Assert.AreEqual(expected, given.repr);
// If we want to get the max and min at the same time, we can stack the
// indices first
// >>> ai_min = np.expand_dims(np.argmin(a, axis=1), axis=1)
// >>> ai_max = np.expand_dims(np.argmax(a, axis=1), axis=1)
// >>> ai = np.concatenate([ai_min, ai_max], axis=axis)
// >> ai
// array([[0, 1],
// [1, 0]], dtype=int64)
// >>> np.take_along_axis(a, ai, axis=1)
// array([[10, 30],
// [40, 60]])
//
var ai_min = np.expand_dims(np.argmin(a, axis:1), axis:1);
var ai_max = np.expand_dims(np.argmax(a, axis:1), axis:1);
given= ai = np.concatenate(new[]{ai_min, ai_max}, axis: 1);
expected=
"array([[0, 1],\n" +
" [1, 0]], dtype=int64)";
Assert.AreEqual(expected, given.repr);
given= np.take_along_axis(a, ai, axis:1);
expected=
"array([[10, 30],\n" +
" [40, 60]])";
Assert.AreEqual(expected, given.repr);
}
from numpy.net.
Nuget packets have been published. I think this closes the issue
from numpy.net.
This fixes the mentioned problem.
As per documentation shouldn't the axis be optional?
The axis to take 1d slices along. If axis is None, the input array is treated as if it had first been flattened to 1d, for consistency with sort and argsort.
from numpy.net.
Related Issues (20)
- np.load of np.savez impossible to get values back out? HOT 3
- np.array leaks memory HOT 12
- Numpy hangs on exit since version 3.10.1.29 (last stable 3.7.1.28) HOT 7
- Support for CuPy HOT 1
- Please Sign and assign StrongName for Numpy Nuget package
- np.split HOT 12
- `Half` type arrays HOT 7
- Set conditions as NDArray Type HOT 3
- fft() failed: βindex -2 is out of bounds for axis 0 with size 1β HOT 9
- Problem with passing imaginery numbers HOT 3
- NDarray of DateTime HOT 3
- Azure AppService and System.DllNotFoundException: Could not load python311.dll with flags RTLD_NOW | RTLD_GLOBAL: python311.dll: cannot open shared object file: No such file or directory HOT 5
- Could not find platform dependent libraries <exec_prefix> HOT 6
- System.TypeLoadException: Could not load type 'Python.Runtime.PyLong' from assembly 'Python.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'. HOT 5
- Numpy.Bare build for Python 3.11 HOT 3
- np.sum(NDArray, axis:1) not supported? HOT 5
- Unable to use Numpy.NET from linux environment HOT 1
- Hello, has SciSharp/NumSharp stopped development and maintenance? HOT 1
- Unable to cast System.Double[][] to NDarray HOT 2
- failed to use "where" in Numpy.NET HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numpy.net.