Get a view of the array as a new data type Parameters ---------- dtype: The dtype by which to view the array. The default, None, results in the view having the same data-type as the original array. order: string 'C' or
(self, dtype=None, order="C")
| 2873 | return clip(self, min, max) |
| 2874 | |
| 2875 | def view(self, dtype=None, order="C"): |
| 2876 | """Get a view of the array as a new data type |
| 2877 | |
| 2878 | Parameters |
| 2879 | ---------- |
| 2880 | dtype: |
| 2881 | The dtype by which to view the array. |
| 2882 | The default, None, results in the view having the same data-type |
| 2883 | as the original array. |
| 2884 | order: string |
| 2885 | 'C' or 'F' (Fortran) ordering |
| 2886 | |
| 2887 | This reinterprets the bytes of the array under a new dtype. If that |
| 2888 | dtype does not have the same size as the original array then the shape |
| 2889 | will change. |
| 2890 | |
| 2891 | Beware that both numpy and dask.array can behave oddly when taking |
| 2892 | shape-changing views of arrays under Fortran ordering. Under some |
| 2893 | versions of NumPy this function will fail when taking shape-changing |
| 2894 | views of Fortran ordered arrays if the first dimension has chunks of |
| 2895 | size one. |
| 2896 | """ |
| 2897 | if dtype is None: |
| 2898 | dtype = self.dtype |
| 2899 | else: |
| 2900 | dtype = np.dtype(dtype) |
| 2901 | mult = self.dtype.itemsize / dtype.itemsize |
| 2902 | |
| 2903 | if order == "C": |
| 2904 | chunks = self.chunks[:-1] + ( |
| 2905 | tuple(ensure_int(c * mult) for c in self.chunks[-1]), |
| 2906 | ) |
| 2907 | elif order == "F": |
| 2908 | chunks = ( |
| 2909 | tuple(ensure_int(c * mult) for c in self.chunks[0]), |
| 2910 | ) + self.chunks[1:] |
| 2911 | else: |
| 2912 | raise ValueError("Order must be one of 'C' or 'F'") |
| 2913 | |
| 2914 | return self.map_blocks( |
| 2915 | chunk.view, dtype, order=order, dtype=dtype, chunks=chunks |
| 2916 | ) |
| 2917 | |
| 2918 | def swapaxes(self, axis1, axis2): |
| 2919 | """Return a view of the array with ``axis1`` and ``axis2`` interchanged. |