View inputs as arrays with at least two dimensions. Parameters ---------- arys1, arys2, ... : array_like One or more array-like sequences. Non-array inputs are converted to arrays. Arrays that already have two or more dimensions are preserved. Returns
(*arys)
| 80 | |
| 81 | @array_function_dispatch(_atleast_2d_dispatcher) |
| 82 | def atleast_2d(*arys): |
| 83 | """ |
| 84 | View inputs as arrays with at least two dimensions. |
| 85 | |
| 86 | Parameters |
| 87 | ---------- |
| 88 | arys1, arys2, ... : array_like |
| 89 | One or more array-like sequences. Non-array inputs are converted |
| 90 | to arrays. Arrays that already have two or more dimensions are |
| 91 | preserved. |
| 92 | |
| 93 | Returns |
| 94 | ------- |
| 95 | res, res2, ... : ndarray |
| 96 | An array, or list of arrays, each with ``a.ndim >= 2``. |
| 97 | Copies are avoided where possible, and views with two or more |
| 98 | dimensions are returned. |
| 99 | |
| 100 | See Also |
| 101 | -------- |
| 102 | atleast_1d, atleast_3d |
| 103 | |
| 104 | Examples |
| 105 | -------- |
| 106 | >>> np.atleast_2d(3.0) |
| 107 | array([[3.]]) |
| 108 | |
| 109 | >>> x = np.arange(3.0) |
| 110 | >>> np.atleast_2d(x) |
| 111 | array([[0., 1., 2.]]) |
| 112 | >>> np.atleast_2d(x).base is x |
| 113 | True |
| 114 | |
| 115 | >>> np.atleast_2d(1, [1, 2], [[1, 2]]) |
| 116 | [array([[1]]), array([[1, 2]]), array([[1, 2]])] |
| 117 | |
| 118 | """ |
| 119 | res = [] |
| 120 | for ary in arys: |
| 121 | ary = asanyarray(ary) |
| 122 | if ary.ndim == 0: |
| 123 | result = ary.reshape(1, 1) |
| 124 | elif ary.ndim == 1: |
| 125 | result = ary[_nx.newaxis, :] |
| 126 | else: |
| 127 | result = ary |
| 128 | res.append(result) |
| 129 | if len(res) == 1: |
| 130 | return res[0] |
| 131 | else: |
| 132 | return res |
| 133 | |
| 134 | |
| 135 | def _atleast_3d_dispatcher(*arys): |