[docs]defdot(a,b,manual=False):""" Dot product of two arrays. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.dot.html """ifmanual:returnsum([ai*biforai,biinzip(a,b)])ifnotis_casadi_type([a,b],recursive=True):return_onp.dot(a,b)else:return_cas.dot(a,b)
[docs]defcross(a,b,axisa=-1,axisb=-1,axisc=-1,axis=None,manual=False):""" Return the cross product of two (arrays of) vectors. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.cross.html """ifmanual:cross_x=a[1]*b[2]-a[2]*b[1]cross_y=a[2]*b[0]-a[0]*b[2]cross_z=a[0]*b[1]-a[1]*b[0]returncross_x,cross_y,cross_zifnotis_casadi_type([a,b],recursive=True):return_onp.cross(a,b,axisa=axisa,axisb=axisb,axisc=axisc,axis=axis)else:ifaxisisnotNone:ifnot(axis==-1oraxis==0oraxis==1):raiseValueError("`axis` must be -1, 0, or 1.")axisa=axisaxisb=axisaxisc=axisifaxisa==-1oraxisa==1:ifnotis_casadi_type(a):a=_cas.DM(a)a=a.Telifaxisa==0:passelse:raiseValueError("`axisa` must be -1, 0, or 1.")ifaxisb==-1oraxisb==1:ifnotis_casadi_type(b):b=_cas.DM(b)b=b.Telifaxisb==0:passelse:raiseValueError("`axisb` must be -1, 0, or 1.")# Compute the cross product, horizontally (along axis 1 of a 2D array)c=_cas.cross(a,b)ifaxisc==-1oraxisc==1:c=c.Telifaxisc==0:passelse:raiseValueError("`axisc` must be -1, 0, or 1.")returnc
[docs]deftranspose(a,axes=None):""" Reverse or permute the axes of an array; returns the modified array. For an array a with two axes, transpose(a) gives the matrix transpose. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html """ifnotis_casadi_type(a,recursive=False):return_onp.transpose(a,axes=axes)else:return_cas.transpose(a)