# Python node for complex math?

**URL:** <https://blenderartists.org/t/python-node-for-complex-math/654997>\
**Category:** Materials and Textures\
**Created:** [October 31, 2015, 11:12am UTC](https://blenderartists.org/t/python-node-for-complex-math/654997 "2015-10-31T11:12:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawn.kearney](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@shawn.kearney](https://blenderartists.org/u/shawn.kearney)\
**Post date:** [October 31, 2015, 11:12am UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/1 "2015-10-31T11:12:57Z")

</div>

From a performance standpoint, is it better to use multiple math nodes or a single python node when dealing with multiple functions?

I realize it will be easier to simplify using a python node (easier to see redundancy), and probably make better organizational sense to use a single python script rather than a dozen math nodes, but are math nodes more or less efficient?

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [October 31, 2015, 12:39pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/2 "2015-10-31T12:39:11Z")

</div>

it is basically the same thing!

unless you want to make a custom nodes in python!

but at least you can do some math using python which is a lot easier I guess

happy cl

---

<div class="post-metadata">

**Author:** ![shawn.kearney](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@shawn.kearney](https://blenderartists.org/u/shawn.kearney)\
**Post date:** [October 31, 2015, 2:23pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/3 "2015-10-31T14:23:04Z")

</div>

So performance-wise Blender sees no difference between the expression (A+B)\*C and two math nodes wired such to get the same result?

Good to know.

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [October 31, 2015, 2:36pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/4 "2015-10-31T14:36:26Z")

</div>

from math done in python it is probably a little faster  
but not from the nodes point of view

mind you still have to write the script to do the math and add the nodes !

and it is not obvious at all

have you already done python nodes in a script ?

happy bl

---

<div class="post-metadata">

**Author:** ![Ace\_Dragon](https://blenderartists.org/user_avatar/blenderartists.org/ace_dragon/32/1067926_2.png) [@Ace\_Dragon](https://blenderartists.org/u/Ace_Dragon)\
**Post date:** [October 31, 2015, 2:45pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/5 "2015-10-31T14:45:42Z")

</div>

If you’re using Cycles, then you can’t use Python expressions anyway (though it can be used to generate a group of nodes).

If you’re using BI, I believe it can have python-defined nodes, but it may be a bit slower if the calculations are actually being done in Python and not C.

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [October 31, 2015, 2:50pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/6 "2015-10-31T14:50:46Z")

</div>

not certain what you mean by Python expressions?

i’v done cycles nodes scripts it does exist

and you can do math in python and use results to set values for cycles nodes too!

mind you can also do more complicated custom nodes too!

happy cl

---

<div class="post-metadata">

**Author:** ![shawn.kearney](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@shawn.kearney](https://blenderartists.org/u/shawn.kearney)\
**Post date:** [October 31, 2015, 3:28pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/7 "2015-10-31T15:28:06Z")

</div>

I meant the mathematical expression “(A+B)\*C” I’ve done a teensy bit of Python in C4D Xpresso to handle rigging math. But not in Blender.

I guess what I am asking is if I have a bunch of math nodes in a cycles material tree would it make sense to compile them all into a single script?

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [October 31, 2015, 3:36pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/8 "2015-10-31T15:36:13Z")

</div>

well if nodes are complex and need a lot of parameters  
it might be worth but not easy to learn it - I can give you thread for this

can you show some nodes set up for what you mean

if you need a very specific nodes set up  
it might be faster to do it in nodes editor

from speed point of view  
math done in python would be faster then doing with nodes  
for simple reason that you are calling nodes API to do the math which is slower then doing it with python math!

happy cl

---

<div class="post-metadata">

**Author:** ![shawn.kearney](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@shawn.kearney](https://blenderartists.org/u/shawn.kearney)\
**Post date:** [October 31, 2015, 3:53pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/9 "2015-10-31T15:53:44Z")

</div>

I do not have anything in particular. Using strings of math nodes can get kind of cumbersome; a formula node with arbitrary inputs would be nice.

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [October 31, 2015, 4:01pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/10 "2015-10-31T16:01:12Z")

</div>

have to remember that nodes do things that you don’t see  
and doing it with math may require more work to get equivalent too!

it is possible but not certain how to do it !

would be nice to see some of the math your talking !

happy cl

---

<div class="post-metadata">

**Author:** ![BaldingWizard](https://blenderartists.org/user_avatar/blenderartists.org/baldingwizard/32/567538_2.png) [@BaldingWizard](https://blenderartists.org/u/BaldingWizard)\
**Post date:** [May 2, 2019, 1:03pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/11 "2019-05-02T13:03:14Z")

</div>

The Node/Maths Expressons (Lite) addon available at [https://github.com/baldingwizard/Blender-Addons/wiki/Dynamic-Maths-Expression](https://github.com/baldingwizard/Blender-Addons/wiki/Dynamic-Maths-Expression) (with the full version available on [Blender Market](https://blendermarket.com/products/node-expressions)) does just that - allows you to enter a textual expression and generates the node group for you. Also allows it to be edited via a custom node within the group, automatically re-building the nodes.

---

<div class="post-metadata">

**Author:** ![Zayd\_Mahmud](https://blenderartists.org/user_avatar/blenderartists.org/zayd_mahmud/32/999680_2.png) [@Zayd\_Mahmud](https://blenderartists.org/u/Zayd_Mahmud)\
**Post date:** [November 26, 2022, 11:25pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/12 "2022-11-26T23:25:00Z")

</div>

is there a way to perform riemann sums/integrate using python in nodes? preferably as a geometry node, but i’d just like to know if its possible

---

<div class="post-metadata">

**Author:** ![Secrop](https://blenderartists.org/user_avatar/blenderartists.org/secrop/32/20093_2.png) [@Secrop](https://blenderartists.org/u/Secrop)\
**Post date:** [November 27, 2022, 1:23pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/13 "2022-11-27T13:23:02Z")

</div>

> [@Zayd\_Mahmud](#):
>
> is there a way to perform riemann sums/integrate using python in nodes?

Not really… at least not without some kind of loop (and plenty of limitations).  
Your best option is to do the integration in python, and then use the results as it would fit better (an image, a gridmesh, etc)

---

<div class="post-metadata">

**Author:** ![RickyBlender](https://blenderartists.org/user_avatar/blenderartists.org/rickyblender/32/7134_2.png) [@RickyBlender](https://blenderartists.org/u/RickyBlender)\
**Post date:** [November 27, 2022, 3:50pm UTC](https://blenderartists.org/t/python-node-for-complex-math/654997/14 "2022-11-27T15:50:14Z")

</div>

i’v seen several python algo to do integral or different ect.  
also available in Nump or Scipy

so easier to do i guess in python with exter. lib  
doing this with nodes is sort of very sluggish and cumbersome

doing it with nodes means that it calculates all the render pixels  
so this takes time !

happy bl
