MCPcopy Create free account
hub / github.com/numpy/numpy / tile

Function tile

numpy/lib/shape_base.py:1186–1274  ·  view source on GitHub ↗

Construct an array by repeating A the number of times given by reps. If `reps` has length ``d``, the result will have dimension of ``max(d, A.ndim)``. If ``A.ndim < d``, `A` is promoted to be d-dimensional by prepending new axes. So a shape (3,) array is promoted to (1, 3) for

(A, reps)

Source from the content-addressed store, hash-verified

1184
1185@array_function_dispatch(_tile_dispatcher)
1186def tile(A, reps):
1187 """
1188 Construct an array by repeating A the number of times given by reps.
1189
1190 If `reps` has length ``d``, the result will have dimension of
1191 ``max(d, A.ndim)``.
1192
1193 If ``A.ndim < d``, `A` is promoted to be d-dimensional by prepending new
1194 axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication,
1195 or shape (1, 1, 3) for 3-D replication. If this is not the desired
1196 behavior, promote `A` to d-dimensions manually before calling this
1197 function.
1198
1199 If ``A.ndim > d``, `reps` is promoted to `A`.ndim by pre-pending 1&#x27;s to it.
1200 Thus for an `A` of shape (2, 3, 4, 5), a `reps` of (2, 2) is treated as
1201 (1, 1, 2, 2).
1202
1203 Note : Although tile may be used for broadcasting, it is strongly
1204 recommended to use numpy&#x27;s broadcasting operations and functions.
1205
1206 Parameters
1207 ----------
1208 A : array_like
1209 The input array.
1210 reps : array_like
1211 The number of repetitions of `A` along each axis.
1212
1213 Returns
1214 -------
1215 c : ndarray
1216 The tiled output array.
1217
1218 See Also
1219 --------
1220 repeat : Repeat elements of an array.
1221 broadcast_to : Broadcast an array to a new shape
1222
1223 Examples
1224 --------
1225 >>> a = np.array([0, 1, 2])
1226 >>> np.tile(a, 2)
1227 array([0, 1, 2, 0, 1, 2])
1228 >>> np.tile(a, (2, 2))
1229 array([[0, 1, 2, 0, 1, 2],
1230 [0, 1, 2, 0, 1, 2]])
1231 >>> np.tile(a, (2, 1, 2))
1232 array([[[0, 1, 2, 0, 1, 2]],
1233 [[0, 1, 2, 0, 1, 2]]])
1234
1235 >>> b = np.array([[1, 2], [3, 4]])
1236 >>> np.tile(b, 2)
1237 array([[1, 2, 1, 2],
1238 [3, 4, 3, 4]])
1239 >>> np.tile(b, (2, 1))
1240 array([[1, 2],
1241 [3, 4],
1242 [1, 2],
1243 [3, 4]])

Callers 4

test_basicMethod · 0.90
test_emptyMethod · 0.90
test_kroncompareMethod · 0.90

Calls 2

reshapeMethod · 0.80
allFunction · 0.50

Tested by 4

test_basicMethod · 0.72
test_emptyMethod · 0.72
test_kroncompareMethod · 0.72