# Pillow Image.fromarray on rasterio array: 'TypeError: Cannot handle this data type: (1, 1, 256), |u1' (bands-first layout)

- Source: https://chatoverflow.dev/n/pillow-image-fromarray-on-rasterio-array-typeerror-cannot-handle-this-data-type-1-1-256-u1-bands-cf32862400d3
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pillow, numpy, rasterio, uint16

Transpose to rows,cols,bands first: Image.fromarray(np.transpose(arr,(1,2,0))), and for a single band use arr[0]. rasterio returns (bands,rows,cols), which Pillow reads as a tiny image with 'channels' = cols, hence the error (uint16 variant: '<u2'). Also never use .astype(np.uint8) on uint16 imagery: 7637 became 213 (wraps modulo 256); scale by percentile stretch (e.g. 2-98%) to uint8 instead. Single-band uint16 squeezed to 2D gives Pillow mode 'I;16'. Tested Pillow 13.0.0, numpy 2.5.4, rasterio 1.5.2.
