# Python 3 Script for GH: error in converting numpy eigenvectors (Rhino8)

**URL:** <https://discourse.mcneel.com/t/python-3-script-for-gh-error-in-converting-numpy-eigenvectors-rhino8/194414>\
**Category:** Scripting\
**Tags:** windows, ghpython, numpy, rhino8, python3\
**Created:** [November 6, 2024, 3:52pm UTC](https://discourse.mcneel.com/t/python-3-script-for-gh-error-in-converting-numpy-eigenvectors-rhino8/194414 "2024-11-06T15:52:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arianna\_Venettoni](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/arianna_venettoni/32/679097_2.png) [@Arianna\_Venettoni](https://discourse.mcneel.com/u/Arianna_Venettoni)\
**Post date:** [November 6, 2024, 3:52pm UTC](https://discourse.mcneel.com/t/python-3-script-for-gh-error-in-converting-numpy-eigenvectors-rhino8/194414/1 "2024-11-06T15:52:18Z")

</div>

Hi everyone.  
I’m nwew to Python so I’m sorry if the question may be silly, but I’m really doing my best.

I’m trying to create a simple script that uses numpy in Python 3 script in GH.  
I want to extract the eigenvectors of a 2x2 symmetrical matrix, but GH doesn’t recognize the output as a list of vectors. I think it sees it as a nested list somehow.

I attach the script:

```auto
import numpy as np

# Create lists
N1 = []
N2 = []
n1 = []
n2 = []

# Assuming N11, N12, and N22 are already defined lists
for i in range(len(N11)):
    # Define 2x2 matrices
    N = np.array([[N11[i], N12[i]],
                  [N12[i], N22[i]]])
    
    # Evaluate eigenvalues and eigenvectors
    eigenvalues, eigenvectors = np.linalg.eig(N)

    # Append eigenvalues to lists
    N1.append(eigenvalues[0].real)
    N2.append(eigenvalues[1].real)
    
    # Append eigenvectors to lists
    n1.append(eigenvectors[:, 0].real.tolist())
    n2.append(eigenvectors[:, 1].real.tolist())

```

the error that occurs is:

System.Collections.Generic.List’1[System-Object]

instead of a list of vectors.

Do you maybe know how to solve the issue? I know I can extract the components and create vectors then, but I would like to know how to extract the list directly.

Thank you very much

---

<div class="post-metadata">

**Author:** ![jovenmark](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jovenmark/32/619433_2.png) [@jovenmark](https://discourse.mcneel.com/u/jovenmark)\
**Post date:** [November 8, 2024, 2:09am UTC](https://discourse.mcneel.com/t/python-3-script-for-gh-error-in-converting-numpy-eigenvectors-rhino8/194414/2 "2024-11-08T02:09:46Z")

</div>

change the category to ‘Scripting’ so someone can see it in there and hopefully you’ll get your answer

edit;  
I’m away on my computer but can you try and see what data type is inside the primary list? eg. N1, N2, etc. if it is a list, flatten it and see if you can get the result that you want

---

<div class="post-metadata">

**Author:** ![Arianna\_Venettoni](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/arianna_venettoni/32/679097_2.png) [@Arianna\_Venettoni](https://discourse.mcneel.com/u/Arianna_Venettoni)\
**Post date:** [November 8, 2024, 12:01pm UTC](https://discourse.mcneel.com/t/python-3-script-for-gh-error-in-converting-numpy-eigenvectors-rhino8/194414/3 "2024-11-08T12:01:46Z")

</div>

The primary list is floats

---

<div class="post-metadata">

**Author:** ![dn.aur](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dn.aur](https://discourse.mcneel.com/u/dn.aur)\
**Post date:** [November 8, 2024, 12:39pm UTC](https://discourse.mcneel.com/t/python-3-script-for-gh-error-in-converting-numpy-eigenvectors-rhino8/194414/4 "2024-11-08T12:39:01Z")

</div>

![grafik](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/7/7/9/779691cbab9ffcb87a480d52dec70b4b9faaae1f.jpeg)

[eigenvalues.gh](https://discourse.mcneel.com/uploads/short-url/ibmGePeDKTAlBr1TeQ8NalnliqM.gh) (7.5 KB)

A few side notes: There is a nice and easy analytical solution for a 2x2 matrix, which requires no numpy.

> <https://math.stackexchange.com/questions/395698/fast-way-to-calculate-eigen-of-2x2-matrix-using-a-formula>

---

<div class="post-metadata">

**Author:** ![Arianna\_Venettoni](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/arianna_venettoni/32/679097_2.png) [@Arianna\_Venettoni](https://discourse.mcneel.com/u/Arianna_Venettoni)\
**Post date:** [November 11, 2024, 3:24pm UTC](https://discourse.mcneel.com/t/python-3-script-for-gh-error-in-converting-numpy-eigenvectors-rhino8/194414/5 "2024-11-11T15:24:48Z")

</div>

Thank you very much! I’m aware that I don’t need numpy to solve the eigenvalues problem for 2x2 tensors, but I wanted to understand the process of scripting so that I can solve more complex problems in the future.  
Thanks again!
