Grasshopper

algorithmic modeling for Rhino

How to convert GH list into Python list to use min/max function

Hey together!

I started to learn a bit of python programming to use it in GH. I tried to search the minimum and maximum value in a list. With sorting the list I get the right output but when I want to use the function min or max it says "None Type is not callable".

I tried to rebuild the list to be sure, that the data types are correct, but it dosn´t work.
Do you know whats the mistake?

Views: 2331

Replies are closed for this discussion.

Replies to This Discussion

I also get it with the numpy functions.

And the classic way with a for loop.

I'm not quite sure what you're asking (or how numpy is involved). But, if you simply want to input a list of data into a GHPython component (and have it pass it as a Python list type you can use min/max on), simply right-click the input parameter and set it to "List Access", you can also set a parameter hint to explicitly set the data type.

Hey! Thats what I already did. But it dosn´t work. Actually in the future I wanna work with numpy so I did it also with there library. But especially for this case I dont´t need it.
When I input a list from Grasshopper (List Access selected) I can´t use the min and max function. That´s my problem. I don´t know why it doesn´t work. For Example my input variable is L and output max, then the code max = max(L) should give me the maximum value. But it dosn´t.

I still can't really tell what you're trying to do, but I suspect you might be overcomplicating things a bit here. This works fine on my system:


Also, be warned that using numpy on Rhino 64 bit (i.e. IronPython 64 bit) will likely be an uphill battle. There are several threads on this topic on the board and on the Discourse forum. An alternative that may work for you is the Math.NET library which runs okay in IronPython.

Edit: Hang on, if you name a variable max, that overrides the name of the function max(). So basically, don't name your variables the same things as existing Python functions.

Ok thanks. Now it works. The funny thing was that your code didn´t worked in the python element I already made. But after deleating all and building up new it worked!

That's probably due you having overridden the max() function in the scope of the GHPython component. When you see this type of behaviour it often helps to close/open the GH definition, which will make these kinds of bugs more explicit and easy to track down (see also this). 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service