Skip to content

Numpy array to C# array #564

Description

@bobred

Environment

  • Pythonnet version: 2.4.0
  • Python version: 3.6 (anaconda)
  • Operating System: Windows 7 (x86)

Details

I am using the code below to use some of the features of pylinac in C#. I would like to know how to convert the dynamic array in to a C# array. In the example below the array structure is 60 rows and 4000 columns.

{[[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]]}

       `PythonEngine.PythonHome = @"C:\Anaconda3";
        
        using (Py.GIL())
        {
            try
            {
                dynamic pl = Py.Import("pylinac");
                dynamic np = Py.Import("numpy");
                dynamic tlog = pl.TrajectoryLog.from_demo();
                tlog.fluence.gamma.calc_map();
                dynamic array = tlog.fluence.actual.array.astype(np.float32, Py.kw("copy",  false));
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }`

Also when debugging in VS 2017 the process slows down when importing Py.Import("pylinac"), any ideas, should this be in a separate post?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions