Given a 3 x 3 matrix S (mechanical stress tensor) of the form
| sxx sxy szx |
S = | sxy syy syz |
| szx syz szz |
I can obtain the 3 eigenvalues (principal stresses) from
import numpy as np
S = np.array([[sxx, sxy, szx],
[sxy, syy, syz],
[szx, syz, szz]])
e_val, e_vec = np.linalg.eig(S)
principal_stress = np.sort(e_val) # 3 principal components sorted from min to max
# with sxx=100, syy=-50, sxy=75, szz=szx=syz=0 the result is
# (-81.07, 0.0, 131.07)
Now, I have a large 2d array in which each column contains the 6 elements
(sxx, syy, szz, sxy, szx, syz) for any given "point of interest (poi)".
There can be hundreds of thousands columns (if not millions) in this array...
| sxx_1 sxx_2 ... sxx_n |
| syy_1 syy_2 ... syy_n |
S_by_poi = | szz_1 szz_2 ... szz_n |
| sxy_1 sxy_2 ... sxy_n |
| szx_1 szx_2 ... szx_n |
| syz_1 syz_2 ... syz_n |
What would be the fastest way to compute the 3 eigenvalues, sort them and put them into an array
P, like this:
| pmin_1 pmin_2 ... pmin_n |
P_by_poi = | pmid_1 pmid_2 ... pmid_n |
| pmax_1 pmax_2 ... pmax_n |
Can I somehow avoid looping over the columns of S in Python? That does not appear to be a good or performant solution ...