I have the following code:
for filename in os.listdir('/home/Downloads/nightlight_geotiffs'):
    if filename.endswith('.tif'):           # take TIFF-files only
        with rasterio.open(os.path.join('/home/ripperflo/Downloads/nightlight_geotiffs', filename)) as f:           # open GeoTiff and store in f
            img = f.read()          # open GeoTiff as 3D numpy array
            matrix = img[0]         # 3D array to 2D array because nighlight images has only one band
            z_norm = stats.zscore(matrix)           # normalize 2D array
            # save to npy file
            np.save('/home/Downloads/nightlight_z-array/', filename, z_norm)
The Code is running so far. the only thing i need to know is: how can I save the numpy array as .npy file with the same name as the origin input file? So the input file is called 'BJ2012_2.tif' and the output file should be called 'BJ2012_2.npy'.