# Python Script - Math - Wrong results

**URL:** <https://forum.dynamobim.com/t/python-script-math-wrong-results/31919>\
**Category:** DesignScript\
**Tags:** python\
**Created:** [February 10, 2019, 11:56am UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919 "2019-02-10T11:56:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 10, 2019, 11:56am UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/1 "2019-02-10T11:56:10Z")

</div>

Hello everyone,

Im learning IronPython, so im trying to wirte down in python script some formulas which i did years before with code blocks and other nodes…  
-So the weird thing is that the inputs for the code block and for python script are the same, but i get different results (look screen1 -yellow results)…  
-in Screen3 you can see that the formula ist pretty much the same for “R1” and “R2” (please ignore the “SUM” (yellow) i will explain it later…  
-so in Screen3 is the formula for “SUM” completly the same (yellow), but then the python script gives me an error…and i dont get any results for “R1” and “R2” also whats ist pretty weird.  
-in the screen4 you can see the error m which is telling about a float in line 17.

So if would say the problems are because i still don´t handle the nomenclature of python, which is not the same for dynamo nodes in math , for example “Math.Pow” and “math.pow”  
So if someone can help me i would be really thankfull, be patient with me…my englisch is not that good!

Thanks

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 10, 2019, 11:56am UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/2 "2019-02-10T11:56:49Z")

</div>

![screen1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/c/3c231049c71170972408a03bacb35a75d199286d.jpeg)

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 10, 2019, 11:57am UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/3 "2019-02-10T11:57:10Z")

</div>

![screen2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/2/92031d3a04874bd5bed32b1f00b95d35e3c21574.jpeg)

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 10, 2019, 11:57am UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/4 "2019-02-10T11:57:31Z")

</div>

![screen3](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/3/f3a633b5f446b558d42caec5ae588572471e802c.jpeg)

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 10, 2019, 11:57am UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/5 "2019-02-10T11:57:50Z")

</div>

![screen4](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/7/073104d3780af5e512f2a5d930f20b9bee061f51.jpeg)

---

<div class="post-metadata">

**Author:** ![Schasfoortyoeri](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Schasfoortyoeri](https://forum.dynamobim.com/u/Schasfoortyoeri)\
**Post date:** [February 10, 2019, 12:32pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/6 "2019-02-10T12:32:05Z")

</div>

i m not sure but i think you need to unwrap elements from IN[2].

You are giving it a List now.

EDIT: Would you mind sharing your .dyn file? i would love to find out for you.

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [February 10, 2019, 2:17pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/7 "2019-02-10T14:17:19Z")

</div>

I think it’s because you are trying to Add to lists. In Python, this will literally join the lists. What it is failing on though, and what is causing the issue is that you are also trying to use math,pow on a list.

Instead, try this…

```
def SumLists(R1,R2,val):
	arr = []
	for a,b in zip(R1,R2):
		arr.append(math.pow(a+b,val))
	return arr

```

`OUT = SumLists(R1,R2,val)`

Now, I noticed something interesting when doing this with Python (Dynamo 2.0.2). When I tried to divide a/b it returns the Floor value. ie 5/2 = 2 or -1/4 = 0 and as an integer. I’m not sure if it just me that is experiencing that though. @Kulkul, have you seen this before?

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [February 10, 2019, 2:36pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/8 "2019-02-10T14:36:16Z")

</div>

My guess is, if you input integers you get integers out, if you transform them to doubles/floats then you’ll get the doubles/floats out as well 🙂

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [February 10, 2019, 2:40pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/9 "2019-02-10T14:40:55Z")

</div>

Huh, go figure. I thought if i was trying to divide a number by another and the result was not an integer it would automatically cast to double. 😄

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [February 10, 2019, 5:29pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/10 "2019-02-10T17:29:19Z")

</div>

Appears to be running into a limit with the number of digits as well… any time I see e^-13 I get worried. If you do the same in excel what values do you get, and is it within a rounding tolerance?

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 10, 2019, 6:58pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/11 "2019-02-10T18:58:20Z")

</div>

yeah sure!

Thanks for you interest! [190210\_math\_python.dyn](https://forum.dynamobim.com/uploads/short-url/p5U2WmO9CyRtiE04LxbeQJ9Xiha.dyn) (16.0 KB)

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 10, 2019, 7:00pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/12 "2019-02-10T19:00:37Z")

</div>

thank you for your advice…i will try it tomorrow or the day after it and tell if it helps

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 10, 2019, 7:07pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/13 "2019-02-10T19:07:22Z")

</div>

Jacob…you dont have to get worried, and i also dont need to try excel…as i told, the method in green is cómpletly correct, i get the results im expecting …  
but the method in pink (python) is giving the wrong results…  
i already posted the script, take a look inside, maybe you understand better whats my problem

---

<div class="post-metadata">

**Author:** ![stillgotme](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@stillgotme](https://forum.dynamobim.com/u/stillgotme)\
**Post date:** [February 11, 2019, 5:58am UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/14 "2019-02-11T05:58:27Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/2/42b7d3cb53040c5b0b56bf9cf5725c1be4c6d12c.jpeg)  
try replacing the R1+R2 in python script with the circled formula in code block

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 11, 2019, 6:30pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/15 "2019-02-11T18:30:36Z")

</div>

Dude look the third Image which i posted!  
“-so in Screen3 is the formula for “SUM” completly the same (yellow), but then the python script gives me an error…and i dont get any results for “R1” and “R2” also whats ist pretty weird.”

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [February 11, 2019, 7:12pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/16 "2019-02-11T19:12:22Z")

</div>

Because R1 and R2 are not values but lists…

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 11, 2019, 7:21pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/17 "2019-02-11T19:21:38Z")

</div>

are you talking about what happens when SUM.append(math.pow((R1+R2),(-1,V))) or what do you mean right now?

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [February 11, 2019, 7:31pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/18 "2019-02-11T19:31:01Z")

</div>

Yes you cannot use math operators on list objects

---

<div class="post-metadata">

**Author:** ![pablo.grillo](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pablo.grillo](https://forum.dynamobim.com/u/pablo.grillo)\
**Post date:** [February 11, 2019, 7:50pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/19 "2019-02-11T19:50:35Z")

</div>

but why ist it possible in a Block, and not with python? like in the block is also a math operator with list objects! and it works perfect

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [February 11, 2019, 8:17pm UTC](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919/20 "2019-02-11T20:17:06Z")

</div>

It is possible. You just need to zip loop through the lists like my earlier example. As @Jonathan.Olesen and i said earlier, you can’t do it on the whole list object, but for each item in the list you can.

[Next page](https://forum.dynamobim.com/t/python-script-math-wrong-results/31919.md?page=2)
