Like netCDF4.stringtochar, but faster and more flexible.
(arr)
| 193 | |
| 194 | |
| 195 | def _numpy_bytes_to_char(arr): |
| 196 | """Like netCDF4.stringtochar, but faster and more flexible.""" |
| 197 | # adapt handling of copy-kwarg to numpy 2.0 |
| 198 | # see https://github.com/numpy/numpy/issues/25916 |
| 199 | # and https://github.com/numpy/numpy/pull/25922 |
| 200 | copy = None if HAS_NUMPY_2_0 else False |
| 201 | # ensure the array is contiguous |
| 202 | arr = np.array(arr, copy=copy, order="C", dtype=np.bytes_) |
| 203 | return arr.reshape(arr.shape + (1,)).view("S1") |
| 204 | |
| 205 | |
| 206 | def char_to_bytes(arr): |
no outgoing calls
no test coverage detected
searching dependent graphs…