Convert inputs to arrays with at least one dimension. Scalar inputs are converted to 1-dimensional arrays, whilst higher-dimensional inputs are preserved. Parameters ---------- arys1, arys2, ... : array_like One or more input arrays. Returns ------- re
(*arys)
| 18 | |
| 19 | @array_function_dispatch(_atleast_1d_dispatcher) |
| 20 | def atleast_1d(*arys): |
| 21 | """ |
| 22 | Convert inputs to arrays with at least one dimension. |
| 23 | |
| 24 | Scalar inputs are converted to 1-dimensional arrays, whilst |
| 25 | higher-dimensional inputs are preserved. |
| 26 | |
| 27 | Parameters |
| 28 | ---------- |
| 29 | arys1, arys2, ... : array_like |
| 30 | One or more input arrays. |
| 31 | |
| 32 | Returns |
| 33 | ------- |
| 34 | ret : ndarray |
| 35 | An array, or tuple of arrays, each with ``a.ndim >= 1``. |
| 36 | Copies are made only if necessary. |
| 37 | |
| 38 | See Also |
| 39 | -------- |
| 40 | atleast_2d, atleast_3d |
| 41 | |
| 42 | Examples |
| 43 | -------- |
| 44 | >>> import numpy as np |
| 45 | >>> np.atleast_1d(1.0) |
| 46 | array([1.]) |
| 47 | |
| 48 | >>> x = np.arange(9.0).reshape(3,3) |
| 49 | >>> np.atleast_1d(x) |
| 50 | array([[0., 1., 2.], |
| 51 | [3., 4., 5.], |
| 52 | [6., 7., 8.]]) |
| 53 | >>> np.atleast_1d(x) is x |
| 54 | True |
| 55 | |
| 56 | >>> np.atleast_1d(1, [3, 4]) |
| 57 | (array([1]), array([3, 4])) |
| 58 | |
| 59 | """ |
| 60 | if len(arys) == 1: |
| 61 | result = asanyarray(arys[0]) |
| 62 | if result.ndim == 0: |
| 63 | result = result.reshape(1) |
| 64 | return result |
| 65 | res = [] |
| 66 | for ary in arys: |
| 67 | result = asanyarray(ary) |
| 68 | if result.ndim == 0: |
| 69 | result = result.reshape(1) |
| 70 | res.append(result) |
| 71 | return tuple(res) |
| 72 | |
| 73 | |
| 74 | def _atleast_2d_dispatcher(*arys): |
searching dependent graphs…