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

Function full

numpy/core/numeric.py:276–331  ·  view source on GitHub ↗

Return a new array of given shape and type, filled with `fill_value`. Parameters ---------- shape : int or sequence of ints Shape of the new array, e.g., ``(2, 3)`` or ``2``. fill_value : scalar or array_like Fill value. dtype : data-type, optional T

(shape, fill_value, dtype=None, order='C', *, like=None)

Source from the content-addressed store, hash-verified

274@set_array_function_like_doc
275@set_module('numpy')
276def full(shape, fill_value, dtype=None, order='C', *, like=None):
277 """
278 Return a new array of given shape and type, filled with `fill_value`.
279
280 Parameters
281 ----------
282 shape : int or sequence of ints
283 Shape of the new array, e.g., ``(2, 3)`` or ``2``.
284 fill_value : scalar or array_like
285 Fill value.
286 dtype : data-type, optional
287 The desired data-type for the array The default, None, means
288 ``np.array(fill_value).dtype``.
289 order : {'C', 'F'}, optional
290 Whether to store multidimensional data in C- or Fortran-contiguous
291 (row- or column-wise) order in memory.
292 ${ARRAY_FUNCTION_LIKE}
293
294 .. versionadded:: 1.20.0
295
296 Returns
297 -------
298 out : ndarray
299 Array of `fill_value` with the given shape, dtype, and order.
300
301 See Also
302 --------
303 full_like : Return a new array with shape of input filled with value.
304 empty : Return a new uninitialized array.
305 ones : Return a new array setting values to one.
306 zeros : Return a new array setting values to zero.
307
308 Examples
309 --------
310 >>> np.full((2, 2), np.inf)
311 array([[inf, inf],
312 [inf, inf]])
313 >>> np.full((2, 2), 10)
314 array([[10, 10],
315 [10, 10]])
316
317 >>> np.full((2, 2), [1, 2])
318 array([[1, 2],
319 [1, 2]])
320
321 """
322 if like is not None:
323 return _full_with_like(
324 like, shape, fill_value, dtype=dtype, order=order)
325
326 if dtype is None:
327 fill_value = asarray(fill_value)
328 dtype = fill_value.dtype
329 a = empty(shape, dtype, order)
330 multiarray.copyto(a, fill_value, casting='unsafe')
331 return a
332
333

Callers

nothing calls this directly

Calls 2

asarrayFunction · 0.70
emptyFunction · 0.50

Tested by

no test coverage detected