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

Function repmat

numpy/matlib.py:330–378  ·  view source on GitHub ↗

Repeat a 0-D to 2-D array or matrix MxN times. Parameters ---------- a : array_like The array or matrix to be repeated. m, n : int The number of times `a` is repeated along the first and second axes. Returns ------- out : ndarray The result

(a, m, n)

Source from the content-addressed store, hash-verified

328 return asmatrix(np.random.randn(*args))
329
330def repmat(a, m, n):
331 """
332 Repeat a 0-D to 2-D array or matrix MxN times.
333
334 Parameters
335 ----------
336 a : array_like
337 The array or matrix to be repeated.
338 m, n : int
339 The number of times `a` is repeated along the first and second axes.
340
341 Returns
342 -------
343 out : ndarray
344 The result of repeating `a`.
345
346 Examples
347 --------
348 >>> import numpy.matlib
349 >>> a0 = np.array(1)
350 >>> np.matlib.repmat(a0, 2, 3)
351 array([[1, 1, 1],
352 [1, 1, 1]])
353
354 >>> a1 = np.arange(4)
355 >>> np.matlib.repmat(a1, 2, 2)
356 array([[0, 1, 2, 3, 0, 1, 2, 3],
357 [0, 1, 2, 3, 0, 1, 2, 3]])
358
359 >>> a2 = np.asmatrix(np.arange(6).reshape(2, 3))
360 >>> np.matlib.repmat(a2, 2, 3)
361 matrix([[0, 1, 2, 0, 1, 2, 0, 1, 2],
362 [3, 4, 5, 3, 4, 5, 3, 4, 5],
363 [0, 1, 2, 0, 1, 2, 0, 1, 2],
364 [3, 4, 5, 3, 4, 5, 3, 4, 5]])
365
366 """
367 a = asanyarray(a)
368 ndim = a.ndim
369 if ndim == 0:
370 origrows, origcols = (1, 1)
371 elif ndim == 1:
372 origrows, origcols = (1, a.shape[0])
373 else:
374 origrows, origcols = a.shape
375 rows = origrows * m
376 cols = origcols * n
377 c = a.reshape(1, a.size).repeat(m, 0).reshape(rows, origcols).repeat(n, 0)
378 return c.reshape(rows, cols)

Callers

nothing calls this directly

Calls 2

asanyarrayFunction · 0.85
reshapeMethod · 0.80

Tested by

no test coverage detected