728x90
728x170

python으로 돼있는걸 C#으로 포팅할 일이 있어서 알아보고 있는 중에 발견한 것들입니다.
 numpy 등 라이브러리를 사용한 경우가 문제있은데 numpy 같은 경우 C#으로 만들어진 것들이 있습니다.


https://github.com/SciSharp/NumSharp

GitHub - SciSharp/NumSharp: High Performance Computation for N-D Tensors in .NET, similar API to NumPy.

High Performance Computation for N-D Tensors in .NET, similar API to NumPy. - GitHub - SciSharp/NumSharp: High Performance Computation for N-D Tensors in .NET, similar API to NumPy.

github.com

일단 사용에는 무리가 없어보이는데 좀 관리가 된 지 오래된 거 같아 보입니다. (마지막 게시 2021-02-15)
Reshape 함수 테스트 ('NumSharp' Nuget 설치)

using NumSharp;

namespace ReshapeTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
            var ndarray = np.arange(12);

            // [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]]
            var array2d = ndarray.reshape(2, 6);

            // [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]
            var array3d = ndarray.reshape(2, 2, 3);
        }
    }
}

결과


https://github.com/SciSharp/Numpy.NET

GitHub - SciSharp/Numpy.NET: C#/F# bindings for NumPy - a fundamental library for scientific computing, machine learning and AI

C#/F# bindings for NumPy - a fundamental library for scientific computing, machine learning and AI - GitHub - SciSharp/Numpy.NET: C#/F# bindings for NumPy - a fundamental library for scientific com...

github.com

그런데 이놈은 Python.Included를 이용해 파이썬 설치가 없어도 된다고 하는데  결국은  Python을 이용하는 것으로 보인다.
Reshape 함수 테스트 ('NumpyDotNet' Nuget 설치)

using NumpyDotNet;

namespace ReshapeTest2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
            var ndarray = np.arange(12);

            // [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]]
            var array2d = ndarray.reshape(2, 6);

            // [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]
            var array3d = ndarray.reshape(2, 2, 3);
        }
    }
}

결과

결과를 보면 알겠지만 내부에 다른 속성들이 많이 있습니다.

이 속성들로도 활용할수 있는 것들이 많이 있을것 같아 보입니다.
Debug 폴더를 가보니 Python 관련된 dll 이없고 Python 이 설치되지도 않았습니다. Python.Included 가 어떤 원리 인지 궁금하네요
사용해 보니 두 패키지가 기존 파이썬 코드를 그대로 차용해서 사용할수 있게 되어있었습니다.

기능도 동일하게 동작하는거 같습니다. (NumSharp 가 오래되서 그런지 다운로드 수가 높긴합니다.)
이제 사용해보게 될텐데 사용해 보면서 어떤지 .. 다음 포스팅에 남기겠습니다.
 
참고
https://github.com/henon/Python.Included

GitHub - henon/Python.Included: A Python.NET based framework enabling .NET libraries to call into Python packages without depend

A Python.NET based framework enabling .NET libraries to call into Python packages without depending on a local Python installation. - GitHub - henon/Python.Included: A Python.NET based framework en...

github.com

 
 
 
 
 
 

728x90
그리드형
Posted by kjun
,