Giter VIP home page Giter VIP logo

Comments (5)

henon avatar henon commented on September 15, 2024 1

you are of course right and I changed that. the change will go into the next release

from numpy.net.

henon avatar henon commented on September 15, 2024

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.

henon avatar henon commented on September 15, 2024

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.

henon avatar henon commented on September 15, 2024

Nuget packets have been published. I think this closes the issue

from numpy.net.

Trippley avatar Trippley commented on September 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.