Return a full array with the same shape and type as a given array. Parameters ---------- a : array_like The shape and data-type of `a` define these same attributes of the returned array. fill_value : scalar Fill value. dtype : data-type, optional
(a, fill_value, order="C", dtype=None, chunks=None, name=None, shape=None)
| 474 | |
| 475 | |
| 476 | def full_like(a, fill_value, order="C", dtype=None, chunks=None, name=None, shape=None): |
| 477 | """ |
| 478 | Return a full array with the same shape and type as a given array. |
| 479 | |
| 480 | Parameters |
| 481 | ---------- |
| 482 | a : array_like |
| 483 | The shape and data-type of `a` define these same attributes of |
| 484 | the returned array. |
| 485 | fill_value : scalar |
| 486 | Fill value. |
| 487 | dtype : data-type, optional |
| 488 | Overrides the data type of the result. |
| 489 | order : {'C', 'F'}, optional |
| 490 | Whether to store multidimensional data in C- or Fortran-contiguous |
| 491 | (row- or column-wise) order in memory. |
| 492 | chunks : sequence of ints |
| 493 | The number of samples on each block. Note that the last block will have |
| 494 | fewer samples if ``len(array) % chunks != 0``. |
| 495 | name : str, optional |
| 496 | An optional keyname for the array. Defaults to hashing the input |
| 497 | keyword arguments. |
| 498 | shape : int or sequence of ints, optional. |
| 499 | Overrides the shape of the result. |
| 500 | |
| 501 | Returns |
| 502 | ------- |
| 503 | out : ndarray |
| 504 | Array of `fill_value` with the same shape and type as `a`. |
| 505 | |
| 506 | See Also |
| 507 | -------- |
| 508 | zeros_like : Return an array of zeros with shape and type of input. |
| 509 | ones_like : Return an array of ones with shape and type of input. |
| 510 | empty_like : Return an empty array with shape and type of input. |
| 511 | zeros : Return a new array setting values to zero. |
| 512 | ones : Return a new array setting values to one. |
| 513 | empty : Return a new uninitialized array. |
| 514 | full : Fill a new array. |
| 515 | """ |
| 516 | |
| 517 | a = asarray(a, name=False) |
| 518 | shape, chunks = _get_like_function_shapes_chunks(a, chunks, shape) |
| 519 | |
| 520 | # if shape is nan we cannot rely on regular full function, we use |
| 521 | # generic map_blocks. |
| 522 | if np.isnan(shape).any(): |
| 523 | return a.map_blocks(partial(np.full_like, dtype=(dtype or a.dtype)), fill_value) |
| 524 | |
| 525 | return full( |
| 526 | shape, |
| 527 | fill_value, |
| 528 | dtype=(dtype or a.dtype), |
| 529 | order=order, |
| 530 | chunks=chunks, |
| 531 | name=name, |
| 532 | meta=a._meta, |
| 533 | ) |
no test coverage detected
searching dependent graphs…