[Numpy-discussion] how to vectorize a row of eigenvalue computations ?
LB
berthe.loic at gmail.com
Thu Oct 16 15:22:13 EDT 2008
I've got an array S of shape (N, 6) with N >> 100000 containing the
six components of a stress field given in N points.
I need to make a lot of computation of principal stresses, which are
in fact the eigenvalues of the stress tensors.
I'm using the basic code described below :
import numpy as np
def calc_principal_stresses(S):
""" Return the principal stress corresponding to the tensor S.
S is interpreted as an array containing [Sx, Sy, Sz, Sxy, Syz,
Szx]
Return array([S3, S2, S1])
"""
p_stresses = np.linalg.eigvalsh( np.array(
[ [ S[0], S[3], S[5]],
[ S[3], S[1], S[4]],
[ S[5], S[4], S[2]],
]))
return p_stresses.sort()
p_stresses = array([ calc_principal_stresses(s) for s in S])
Aside putting the sort function outside the loop, is there any way to
optimize or vectorize this kind of operation ?
Regards,
--
LB
More information about the NumPy-Discussion
mailing list