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