ฉันจะใช้ตัวแปรเป็นชื่อไฟล์ในพาธของไฟล์เพื่อเก็บอาร์เรย์ numpy ในไฟล์ numpy ได้อย่างไร [ทำซ้ำ]

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)
DIR = '/home/Downloads/nightlight_geotiffs'
files = [x for x in os.listdir(DIR) if x.endswith('.tif')] # gives you all the list of ('.tif files')
NUMPY_DIR = '/home/Downloads/nightlight_z-array/'

for file in files:
    path = os.path.join(DIR, file)
    with open(path,'r') as f:            
        img = f.read()                    
        matrix = img[0]                    
        z_norm = stats.zscore(matrix)           
        file= file.split('.')[0]
        new_file= os.path.join(NUMPY_DIR,f'{file}')
        
       # save to npy file
        np.save(new_file, z_norm)