Write a NumPy program to join a sequence of arrays along a new axis

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

Write a NumPy program to join a sequence of arrays along a new axis.

الأجوبة

import numpy as np    
x = np.array([1, 2, 3])
y = np.array([2, 3, 4])
print("Original arrays:")
print(x)
print(y)
print("Sequence of arrays along a new axis:")
print(np.vstack((x, y)))
x = np.array([[1], [2], [3]])
y = np.array([[2], [3], [4]])
print("\nOriginal arrays:")
print(x)
print()
print(y)
print("Sequence of arrays along a new axis:")
print(np.vstack((x, y)))

Sample Output:

Original arrays:
[1 2 3]
[2 3 4]
Sequence of arrays along a new axis:
[[1 2 3]
 [2 3 4]]

Original arrays:
[[1]
 [2]
 [3]]

[[2]
 [3]
 [4]]
Sequence of arrays along a new axis:
[[1]
 [2]
 [3]
 [2]
 [3]
 [4]]
هل كان المحتوى مفيد؟

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

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