Created
May 13, 2012 19:08
-
-
Save astrojuanlu/2689795 to your computer and use it in GitHub Desktop.
Símbolo de Levi-Civita en Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| # Símbolo de Levi-Civita en Python utilizando listas por comprensión | |
| # Fórmula extraída de http://en.wikipedia.org/wiki/Levi-Civita_symbol#Three_dimensions | |
| # Válido para Python 2 y 3 | |
| # | |
| # Juan Luis Cano Rodríguez <juanlu001@gmail.com> | |
| from __future__ import print_function | |
| import numpy as np | |
| e = np.array([[[int((i - j) * (j - k) * (k - i) / 2) for k in range(3)] for j in range(3)] for i in range(3)]) | |
| print(e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [[[ 0. 0. 0.] | |
| [ 0. 0. 1.] | |
| [ 0. -1. 0.]] | |
| [[ 0. 0. -1.] | |
| [ 0. 0. 0.] | |
| [ 1. 0. 0.]] | |
| [[ 0. 1. 0.] | |
| [-1. 0. 0.] | |
| [ 0. 0. 0.]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to point out that the Levi-Civita tensor is available in
sympy.Here's a code equivalent to the one above.
The generalization to higher dimensions is done by adding extra dimensions and increasing the bounds of each
rangein the loops.