Skip to main content

Cross Product between Two Vectors

This is an example of how to use the csdl.cross() function to compute the cross product between two vectors.

from csdl_om import Simulatorfrom csdl import Modelimport csdlimport numpy as np

class ExampleVectorVector(Model):
    def define(self):        # Creating two vectors        vecval1 = np.arange(3)        vecval2 = np.arange(3) + 1
        vec1 = self.declare_variable('vec1', val=vecval1)        vec2 = self.declare_variable('vec2', val=vecval2)
        # Vector-Vector Cross Product        self.register_output('VecVecCross',                             csdl.cross(vec1, vec2, axis=0))

sim = Simulator(ExampleVectorVector())sim.run()
print('vec1', sim['vec1'].shape)print(sim['vec1'])print('vec2', sim['vec2'].shape)print(sim['vec2'])print('VecVecCross', sim['VecVecCross'].shape)print(sim['VecVecCross'])
[0. 1. 2.]vec2 (3,)[1. 2. 3.]VecVecCross (3,)[-1.  2. -1.]