Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I need the python equivalent code in c# #45

Closed
gurelsoycaner opened this issue Jun 25, 2020 · 9 comments
Closed

I need the python equivalent code in c# #45

gurelsoycaner opened this issue Jun 25, 2020 · 9 comments

Comments

@gurelsoycaner
Copy link

I'm having problem convert this py code

ex = (P2 - P1)/(numpy.linalg.norm(P2 - P1))

and
d = numpy.linalg.norm(P2 - P1)

and
ez = numpy.cross(ex,ey)

I'm using .net core 3.1 and I've installed this.

please I need the python equivalent of the above code in c#.

thanks in advance.

Nelly

@henon
Copy link
Contributor

henon commented Jun 25, 2020

Sure, where is your problem? This test passes fine

        [TestMethod]
        public void QuestionByGurelsoycaner()
        {
            //>>> import numpy as np
            //>>> P1 = np.array([1, 2, 3, 4])
            //>>> P2 = np.array([4, 3, 2, 1])
            //>>> ex = (P2 - P1) / (np.linalg.norm(P2 - P1))
            //>>> ex
            //array([0.67082039, 0.2236068, -0.2236068, -0.67082039])
            var P1 = np.array(new[] { 1, 2, 3, 4 });
            var P2 = np.array(new[] { 4, 3, 2, 1 });
            var ex = (P2 - P1) / (np.linalg.norm(P2 - P1));
            Assert.AreEqual("array([ 0.67082039,  0.2236068 , -0.2236068 , -0.67082039])", ex.repr);
        }

@gurelsoycaner
Copy link
Author

thanks for responding this fast,
I've installed NumSharp from nuget into my project can I cannot find "np.linalg.norm" and numpy.cross(ex,ey) method/function, infact there not intellisense as it seems omitted.

In python you can do "ex = (P2 - P1)/(numpy.linalg.norm(P2 - P1)) and ez = numpy.cross(ex,ey)" and I need to perform the same operation in my c# code.

should u try it yourself I'm sure you will see what I mean.

pls your help it needed.

@henon
Copy link
Contributor

henon commented Jun 25, 2020

I just tried, but from the source code. which nuget package version?

@gurelsoycaner
Copy link
Author

Install-Package NumSharp -Version 0.20.5

image

@gurelsoycaner
Copy link
Author

the same problem with np.cross

image

@henon
Copy link
Contributor

henon commented Jun 25, 2020

yeah, I see, NumSharp is a different repository. This is Numpy.NET.

@gurelsoycaner
Copy link
Author

hooo, sorry abt that,

I've just installed

and the problem its same. method missing

image

@henon
Copy link
Contributor

henon commented Jun 25, 2020

NumpyDotNet is not right either. Install this: https://www.nuget.org/packages/Numpy/

@gurelsoycaner
Copy link
Author

thank you very very much sir, GOD BLESS.
you've just save my day.

@henon henon closed this as completed Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants