@@ -20,31 +20,39 @@ Args:
20
20
21
21
### Example
22
22
23
+ #### Concatenate along axis 0
24
+
23
25
``` python
24
26
import numpy as np
25
27
# creating 2 arrays
26
28
arr1 = np.array([1 2 3 ],[7 8 9 ])
27
29
arr2 = np.array([4 5 6 ],[10 11 12 ])
28
30
29
- # concatenate along axis 0
30
31
result_1 = np.concatenate((arr1, arr2), axis = 0 )
31
- print (" Concatenation along axis 0:" )
32
32
print (result_1)
33
- """ Output- Concatenation along axis 0:
33
+ ```
34
+
35
+ #### Output
36
+ ```
34
37
[[ 1 2 3]
35
38
[ 7 8 9]
36
39
[ 4 5 6]
37
- [10 11 12]] """
40
+ [10 11 12]]
41
+ ```
38
42
39
- # concatenate along axis 1
43
+ #### Concatenate along axis 1
44
+
45
+ ``` python
40
46
result_2 = np.concatenate((arr1, arr2), axis = 1 )
41
- print (" Concatenation along axis 1:" )
42
47
print (result_2)
43
- """ Output- Concatenation along axis 1:
44
- [[ 1 2 3 4 5 6 ]
45
- [ 7 8 9 10 11 12]] """
48
+ ```
46
49
50
+ #### Output
47
51
```
52
+ [[ 1 2 3 4 5 6 ]
53
+ [ 7 8 9 10 11 12]]
54
+ ```
55
+
48
56
## np.vstack
49
57
50
58
Vertical stacking of arrays (row-wise).
59
67
- arrays: Sequence of arrays to stack.
60
68
61
69
### Example
70
+
62
71
``` python
63
72
import numpy as np
64
73
# create arrays
@@ -67,12 +76,16 @@ arr2 = np.array([4 5 6],[10 11 12])
67
76
68
77
result = np.vstack((arr1, arr2))
69
78
print (result)
70
- """ output-
79
+ ```
80
+
81
+ #### Output
82
+ ```
71
83
[[ 1 2 3]
72
84
[ 7 8 9]
73
85
[ 4 5 6]
74
- [10 11 12]] """
86
+ [10 11 12]]
75
87
```
88
+
76
89
## 3. np.hstack
77
90
78
91
Stacks arrays horizontally (column-wise).
@@ -96,9 +109,12 @@ arr2 = np.array([4 5 6],[10 11 12])
96
109
97
110
result = np.hstack((arr1, arr2))
98
111
print (result)
99
- """ output-
112
+ ```
113
+
114
+ #### Output
115
+ ```
100
116
[[ 1 2 3] [ 4 5 6]
101
- [ 7 8 9] [10 11 12]] """
117
+ [ 7 8 9] [10 11 12]]
102
118
```
103
119
104
120
## np.dstack
@@ -123,14 +139,17 @@ arr2 = np.array([4 5 6],[10 11 12])
123
139
124
140
result = np.dstack((arr1, arr2))
125
141
print (result)
126
- """ output-
142
+ ```
143
+
144
+ #### Output
145
+ ```
127
146
[[[ 1 4]
128
147
[ 2 5]
129
148
[ 3 6]]
130
149
131
150
[[ 7 10]
132
151
[ 8 11]
133
- [ 9 12]]] """
152
+ [ 9 12]]]
134
153
```
135
154
136
155
## np.stack
@@ -154,12 +173,15 @@ arr2 = np.array([4 5 6],[10 11 12])
154
173
155
174
result = np.stack((arr1, arr2), axis = 0 )
156
175
print (result)
157
- """ output-
176
+ ```
177
+
178
+ #### Output
179
+ ```
158
180
[[[ 1 2 3]
159
181
[ 7 8 9]]
160
182
161
183
[[ 4 5 6]
162
- [10 11 12]]] """
184
+ [10 11 12]]]
163
185
```
164
186
165
187
# Concatenation with Mixed Dimensions
@@ -168,28 +190,34 @@ When concatenating arrays with different shapes, it's often necessary to reshape
168
190
169
191
## Example
170
192
193
+ #### Concatenate along axis 0
194
+
171
195
``` python
172
196
arr1 = np.array([[1 , 2 , 3 ], [4 , 5 , 6 ]])
173
197
arr2 = np.array([7 , 8 , 9 ])
174
198
175
- # Concatenate along axis 0
176
199
result_0= np.concatenate((arr1, arr2[np.newaxis, :]), axis = 0 )
177
- print (" Concatenation along axis 0:" )
178
200
print (result_0)
179
- """ output-
180
- Concatenation along axis 0:
201
+ ```
202
+
203
+ #### Output
204
+ ```
181
205
[[1 2 3]
182
206
[4 5 6]
183
- [7 8 9]] """
207
+ [7 8 9]]
208
+ ```
209
+
210
+ #### Concatenate along axis 1
184
211
185
- # Concatenate along axis 1
212
+ ``` python
186
213
result_1 = np.concatenate((arr1, arr2[:, np.newaxis]), axis = 1 )
187
- print (" \n Concatenation along axis 1:" )
188
214
print (result_1)
189
- """ output-
190
- Concatenation along axis 1:
215
+ ```
216
+
217
+ #### Output
218
+ ```
191
219
[[1 2 3 7]
192
- [4 5 6 8]] """
220
+ [4 5 6 8]]
193
221
```
194
222
195
223
0 commit comments