Return an array of ones 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. dtype : data-type, optional Overrides the data type of the resu
(a, dtype=None, order="C", chunks=None, name=None, shape=None)
| 349 | |
| 350 | |
| 351 | def ones_like(a, dtype=None, order="C", chunks=None, name=None, shape=None): |
| 352 | """ |
| 353 | Return an array of ones with the same shape and type as a given array. |
| 354 | |
| 355 | Parameters |
| 356 | ---------- |
| 357 | a : array_like |
| 358 | The shape and data-type of `a` define these same attributes of |
| 359 | the returned array. |
| 360 | dtype : data-type, optional |
| 361 | Overrides the data type of the result. |
| 362 | order : {'C', 'F'}, optional |
| 363 | Whether to store multidimensional data in C- or Fortran-contiguous |
| 364 | (row- or column-wise) order in memory. |
| 365 | chunks : sequence of ints |
| 366 | The number of samples on each block. Note that the last block will have |
| 367 | fewer samples if ``len(array) % chunks != 0``. |
| 368 | name : str, optional |
| 369 | An optional keyname for the array. Defaults to hashing the input |
| 370 | keyword arguments. |
| 371 | shape : int or sequence of ints, optional. |
| 372 | Overrides the shape of the result. |
| 373 | |
| 374 | Returns |
| 375 | ------- |
| 376 | out : ndarray |
| 377 | Array of ones with the same shape and type as `a`. |
| 378 | |
| 379 | See Also |
| 380 | -------- |
| 381 | zeros_like : Return an array of zeros with shape and type of input. |
| 382 | empty_like : Return an empty array with shape and type of input. |
| 383 | zeros : Return a new array setting values to zero. |
| 384 | ones : Return a new array setting values to one. |
| 385 | empty : Return a new uninitialized array. |
| 386 | """ |
| 387 | |
| 388 | a = asarray(a, name=False) |
| 389 | shape, chunks = _get_like_function_shapes_chunks(a, chunks, shape) |
| 390 | |
| 391 | # if shape is nan we cannot rely on regular ones function, we use |
| 392 | # generic map_blocks. |
| 393 | if np.isnan(shape).any(): |
| 394 | return a.map_blocks(partial(np.ones_like, dtype=(dtype or a.dtype))) |
| 395 | |
| 396 | return ones( |
| 397 | shape, |
| 398 | dtype=(dtype or a.dtype), |
| 399 | order=order, |
| 400 | chunks=chunks, |
| 401 | name=name, |
| 402 | meta=a._meta, |
| 403 | ) |
| 404 | |
| 405 | |
| 406 | def zeros_like(a, dtype=None, order="C", chunks=None, name=None, shape=None): |
nothing calls this directly
no test coverage detected
searching dependent graphs…