Interpolate in GHpython without Numpy

Is there a method to do 1 dimensional linear interpolate (like the one in Numpy) without having to install GHpython Remote and python 2+?
I have checked Rhino.Geometry.Interpolator but it seems can only be constructed with uniformly spanned data series.
Thanks.

Have you tried the Grasshopper Component, Maths → Util → Interpolate_data ?

The GhPython statistics module (a backport from Python 3.4?) doesn’t contain linear_regression - the v 3.10 one is needed for that which is by no means guaranteed to be GhPython compatible

Hi James, thanks for your reply. Yes I have tried, and it seems to work the same as the Rhino.Geometry.Interpolator() one.

I am trying to do this

Where the parameter is not uniformly distributed.

Please correct me if I’m being naive.

You’re not being naive at all - I didn’t realise they had the same code behind them.

Does it still require a uniform distribution if you right click it and select one of the other options, e…g cubic?

Yes, I’m afraid so. The option only changes the way of interpolation after the interpolator object has been constructed. And as long as the constructor only takes 1 dimensional collection as input, the indices of the items inside the interpolator would always be 0, 1, 2, 3, 4 … (Up to what I can find now). Thus, uniform.

I’ve been trying to input 2 dimensional collections (e.g. Intervals, Point2d, nested list). But I’m just abusing the API, it seems to be deisnged with only 1 dimensional.

Well I do have a work around.

Using subprocess to pass the data to external python. Do interpolation with Numpy. Then transfer the data back to grasshopper.

But in this case, I will have 2 files to do this work. I really wish to hear about more elegant ways.

Rhino 8 comes with native CPython 3. So we can finally run numpy without jumping through hoops :raised_hands:

I have my credit cards ready, really.

I’ll uprade immediately when 8 is officially out.

You can download the beta today for free and give it whirl if you can’t wait :partying_face:

Hi,

just like to mention that in Rhino below V8, you are coding in the .NET ecosystem with IronPython and there is of course a rich set of math libraries, such as Math .NET.
https://numerics.mathdotnet.com/api/MathNet.Numerics/Interpolate.htm

Other than that, I think for something like linear regression, it shouldn’t be a big deal to code it from scratch.
Although I have to admit, that Python 3 ecosystem with Numpy is quite a nice thing to use.
But doing Interprocess Communication just for this is definitely an overkill.

3 Likes

Hi, Tom. Thanks for your suggestion, I will have a try.

This seems to be a new thing to me and I cannot give a feedback very soon whether I can work it out.

But this helps, thanks.

This tutorial on the old forum by @piac might help:

1 Like

Yes, using Math.NET works.

Thanks for every one’s input. I cannot tick 2 solutions, but by following the combination of the above 2, things worked out easily.

Code is dependent on the installtion of Math.NET package, so I’m not gonna upload a file, just following the guide would work

2 Likes