Write a NumPy program to generate inner, outer, and cross products of matrices and vectors

  • برمجة بايثون

Write a NumPy program to generate inner, outer, and cross products of matrices and vectors.

الأجوبة

import numpy as np
x = np.array([1, 4, 0], float)
y = np.array([2, 2, 1], float)
print("Matrices and vectors.")
print("x:")
print(x)
print("y:")
print(y)
print("Inner product of x and y:")
print(np.inner(x, y))
print("Outer product of x and y:")
print(np.outer(x, y))
print("Cross product of x and y:")
print(np.cross(x, y))

Sample Output:

Matrices and vectors.                                                  
x:                                                                     
[ 1.  4.  0.]                                                          
y:                                                                     
[ 2.  2.  1.]                                                          
Inner product of x and y:                                              
10.0                                                                   
Outer product of x and y:                                              
[[ 2.  2.  1.]                                                         
 [ 8.  8.  4.]                                                         
 [ 0.  0.  0.]]                                                        
Cross product of x and y:                                              
[ 4. -1. -6.]
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...