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