Write a NumPy program to create to concatenate two given arrays of shape (2, 2) and (2,1)

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

Write a NumPy program to create to concatenate two given arrays of shape (2, 2) and (2,1).

الأجوبة

import numpy as np 
nums1 = np.array([[4.5, 3.5],
                 [5.1, 2.3]])
nums2 = np.array([[1],
                  [2]])
print("Original arrays:")
print(nums1)
print(nums2)
print("\nConcatenating the said two arrays:")
print(np.concatenate((nums1, nums2), axis=1))

Sample Output:

Original arrays:
[[4.5 3.5]
 [5.1 2.3]]
[[1]
 [2]]

Concatenating the said two arrays:
[[4.5 3.5 1. ]
 [5.1 2.3 2. ]]
هل كان المحتوى مفيد؟

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

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