Calculate .argmax() across 5000 xarrays

I have around 5000 geotiff files each of (25000,25000) with data value float32.
I wanted to calculate .argmax() across 5000 arrays.
So, first tried by merging the data arrays.

import xarray, rioxarray
rasters = [rioxarray.open_rasterio(f) for f in files]
merged = xarray.concat(rasters,dim=“band”)

I m struggled with the following error.

Traceback (most recent call last):
File “”, line 42, in
File “/home/laura/.local/lib/python3.6/site-packages/xarray/core/”, line 192, in concat
objs, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs
File “/home/laura/.local/lib/python3.6/site-packages/xarray/core/”, line 527, in _dataarray_concat
File “/home/laura/.local/lib/python3.6/site-packages/xarray/core/”, line 384, in _dataset_concat
align(*datasets, join=join, copy=False, exclude=[dim], fill_value=fill_value)
File “/home/laura/.local/lib/python3.6/site-packages/xarray/core/”, line 354, in align
copy=copy, fill_value=fill_value, indexers=valid_indexers
File “/home/laura/.local/lib/python3.6/site-packages/xarray/core/”, line 2630, in reindex
File “/home/laura/.local/lib/python3.6/site-packages/xarray/core/”, line 2661, in _reindex
File “/home/laura/.local/lib/python3.6/site-packages/xarray/core/”, line 567, in reindex_variables
“index has duplicate values” % dim
ValueError: cannot reindex or align along dimension ‘x’ because the index has duplicate values

I tried by putting compat = "override" or no_conflicts. But, I got same error.

Could someone help me ?

Do you know why your x coordinate has duplicate values? This is preventing Xarray from aligning the arrays.

More generally, do you know a priori that all the arrays have the same CRS and coordinates?