NumPy ऑनलाइन चलाएँ

Concatenate NumPy Arrays

Stack arrays on top of each other or side by side with np.concatenate, vstack and hstack.

  • मध्यम
  • 2 मिनट में पढ़ें
  • 1 चलाने योग्य उदाहरण
आप क्या सीखेंगे
  • np.concatenate with axis=0 and axis=1
  • vstack and hstack shortcuts
  • Shape rules for joining
concatenate(([[1, 2], [3, 4]], [[5, 6]]), axis=0)
1
2
3
4
5
6

Join along one axis

चुने गए axis के अलावा बाकी dimensions compatible होने चाहिए।

मुख्य बातें

  1. axis=0 adds rows; the column counts must match.
  2. axis=1 adds columns; the row counts must match.
  3. np.vstack and np.hstack are shortcuts for the two cases.

इसका उपयोग कब करें?

  • कई मानों पर vectorized गणना करें।
  • Arrays, matrices और scientific data संसाधित करें।
  • Data science और machine learning के लिए data तैयार करें।

उदाहरण कोड

कोड चलाएँ →
main.py
import numpy as np

first = np.array([[1, 2], [3, 4]])
second = np.array([[5, 6]])

print(np.concatenate((first, second), axis=0))
इस उदाहरण के लिए Run बटन बनाएँ

अपेक्षित आउटपुट

[[1 2]
 [3 4]
 [5 6]]

यह कैसे काम करता है

axis जोड़ने की दिशा तय करता है; stack एक नया axis बनाता है।

मान बदलें और Python इंस्टॉल किए बिना CodeUtility ऑनलाइन Python कंपाइलर में प्रोग्राम चलाएँ।

अभ्यास के कार्य

बड़े dataset पर जाने से पहले input बदलें और edge cases की जाँच करें।

  1. Shape और dtype बदलकर देखें।
  2. Negative, decimal और missing values जाँचें।
  3. बड़े array पर execution time मापें।
Python IDE में चलाएँ →