<jupyter_start><jupyter_text>Joining NumPy Arrays<jupyter_code>Joining means putting contents of two or more arrays in a single array.
In SQL we join tables based on a key, whereas in NumPy we join arrays by axes.
We pass a sequence of arrays that we want to join to the concatenate() function, along with the axis. If axis is not explicitly passed, it is taken as 0.<jupyter_output><empty_output><jupyter_text>Join two arrays<jupyter_code>import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.concatenate((arr1, arr2))

print(arr)<jupyter_output>[1 2 3 4 5 6]<jupyter_text>Join two 2-D arrays along rows (axis=1):<jupyter_code>import numpy as np

arr1 = np.array([[1, 2], [3, 4]])

arr2 = np.array([[5, 6], [7, 8]])

arr = np.concatenate((arr1, arr2), axis=1)

print(arr)<jupyter_output>[[1 2 5 6]
 [3 4 7 8]]<jupyter_text>Joining Arrays Using Stack Functions<jupyter_code>Stacking is same as concatenation, the only difference is that stacking is done along a new axis.
We can concatenate two 1-D arrays along the second axis which would result in putting them one over the other, ie. stacking.
We pass a sequence of arrays that we want to join to the concatenate() method along with the axis. If axis is not explicitly passed it is taken as 0.<jupyter_output><empty_output><jupyter_text>import numpy as nparr1 = np.array([1, 2, 3])arr2 = np.array([4, 5, 6])arr = np.stack((arr1, arr2), axis=1)print(arr)<jupyter_code># Stacking Along Rows<jupyter_output><empty_output><jupyter_text>NumPy provides a helper function: hstack() to stack along rows.<jupyter_code>import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.hstack((arr1, arr2))

print(arr)<jupyter_output>[1 2 3 4 5 6]<jupyter_text>Stacking Along Columns<jupyter_code>NumPy provides a helper function: vstack()  to stack along columns.<jupyter_output><empty_output><jupyter_text>import numpy as nparr1 = np.array([1, 2, 3])arr2 = np.array([4, 5, 6])arr = np.vstack((arr1, arr2))print(arr)<jupyter_code># Stacking Along Height (depth)<jupyter_output><empty_output><jupyter_text>NumPy provides a helper function: dstack() to stack along height, which is the same as depth.<jupyter_code>import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.dstack((arr1, arr2))

print(arr)<jupyter_output>[[[1 4]
  [2 5]
  [3 6]]]
{'fraction_non_alphanumeric': 0.12314853999153619, 'fraction_numerical': 0.040203131612357175, 'mean_word_length': 5.4945054945054945, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '207001', 'license': 'MIT', 'n_tokens_mistral': 927, 'n_tokens_neox': 863, 'n_words': 292, 'path': '10. NumPy Joining Array.ipynb', 'repo_name': 'Vinaykumargond/Python-Numpy-Tutorial', 'size': '2363'}