Giter VIP home page Giter VIP logo

Comments (4)

henon avatar henon commented on August 11, 2024 1

I fixed it. Now the output looks correct:

Control:
[[-1  0  0]
 [ 0  0  0]
 [ 0  0  0]]
Test:
[[-1  0  0]
 [ 0  0  0]
 [ 0  0  0]]
Test flipped on axis 0:
[[ 0  0  0]
 [ 0  0  0]
 [-1  0  0]]
Control extracted back to C#:
-1 0 0 0 0 0 0 0 0 
Test extracted back to C#:
0 0 0 0 0 0 -1 0 0 

It was due to the flipped array's data layout not being contiguous. In such cases GetData now calls np.ascontiguous internally and gives back the data of the contiguous copy.

from numpy.net.

henon avatar henon commented on August 11, 2024

This is very interesting. Could you give me a short piece of code which I can fashion into a unit test to reproduce and fix it?

from numpy.net.

gitpiped avatar gitpiped commented on August 11, 2024

Here you go!

`using System;
using Numpy;

namespace Test
{
class Program
{
static void Main(string[] args)
{
NumpyGlitch();
}

    static void NumpyGlitch()
    {

        int[,] X = new int[3, 3];
        X[0, 0] = -1;

        NDarray npX = np.array(X, dtype: np.int32); // control
        NDarray npY = np.array(X, dtype: np.int32); // test

        Console.WriteLine("Control:");
        Console.WriteLine(npX);

        Console.WriteLine("Test:");
        Console.WriteLine(npY);

        // flip on the row axis
        npY = np.flip(npY, new int[] { 0 });
        Console.WriteLine("Test flipped on axis 0:");
        Console.WriteLine(npY);

        // get their data
        int[] cX = npX.GetData<int>(); 
        int[] cY = npY.GetData<int>();

        Console.WriteLine("Control extracted back to C#:");
        PrintArray(cX); // control is fine
        Console.WriteLine("Test extracted back to C#:");
        PrintArray(cY); // this one has some funny business going on!

    }

    static void PrintArray(int[] array)
    {
        for (int i = 0; i < array.Length; i++)
        {
            Console.Write("{0} ", array[i]);
        }
        Console.WriteLine();
    }
}

}`

Thanks!

from numpy.net.

gitpiped avatar gitpiped commented on August 11, 2024

Great, thanks!

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.