MCPcopy
hub / github.com/numpy/numpy / repmat

Function repmat

numpy/matlib.py:332–380  ·  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

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

Callers

nothing calls this directly

Calls 2

asanyarrayFunction · 0.85
reshapeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…