-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLeviCivita.py
More file actions
41 lines (31 loc) · 1006 Bytes
/
LeviCivita.py
File metadata and controls
41 lines (31 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 26 19:29:06 2017
@author: luke
Levi-Civita in python:
https://stackoverflow.com/questions/20908754/how-to-speed-up-a-vector-cross-product-calculation
getitem with multiple arguments:
https://stackoverflow.com/questions/1685389/possible-to-use-more-than-one-argument-on-getitem
"""
import numpy as np
def make_Levi_Civita():
eijk = np.zeros((3, 3, 3))
eijk[0, 1, 2] = eijk[1, 2, 0] = eijk[2, 0, 1] = 1
eijk[0, 2, 1] = eijk[2, 1, 0] = eijk[1, 0, 2] = -1
return eijk
eijk = make_Levi_Civita()
class LeviCivita(object):
def __init__(self):
self.lc = eijk
def __call__(self,i,j,k):
return self.lc[i,j,k]
def __getitem__(self, pos):
i,j,k = pos
return self.lc[i,j,k]
def __repr__(self):
return 'LeviCivita({})'.format(self.lc)
def __str__(self):
return 'LeviCivita({})'.format(self.lc)
if __name__ == '__main__':
self = LeviCivita()