ValueError: operands could not be broadcast together with shapes (15,1) (256,256) (256,256)

Hi
Why I have this error in this line" result[i,:,:,0] = np.where(type_map == 1, inst_map, result[i,:,:,0])"?
Please help me
Traceback (most recent call last):
File “transform_for_metrics.py”, line 54, in
result[i,:,:,0] = np.where(type_map == 1, inst_map, result[i,:,:,0])
File “<array_function internals>”, line 6, in where
ValueError: operands could not be broadcast together with shapes (15,1) (256,256) (256,256)

path_to_folder = “/content/drive/MyDrive/0.9-0.1/outputs/mat/”

file_format = “.mat”

read all .mat or .npy files from directory

files = []

for i in os.listdir(path_to_folder):

if file_format == ".npy":

    if i.endswith('.npy'):

        files.append(np.load(path_to_folder + "/" + i))

if file_format == ".mat": #and i != "fold3_148.mat":

    if i.endswith('.mat'):

        mat_dict = sio.loadmat(path_to_folder + "/" + i)

        # add file number to dictionary (file name should be in format "fold3_105.mat" with 105 as the file number)

        #print(mat_dict)

        x = i.split(".") 

        

        #x = x[0].split("_")

        x = int(x[0])

        

        mat_dict['filenumber'] = x

        files.append(mat_dict)

        #print("successfullly appended file " + i)

sort files numerically by file number

files_sorted = sorted(files, key=lambda k: k[‘filenumber’])

transform format

result = np.zeros((len(files_sorted), 256, 256, 6))

for i, pred in enumerate(files_sorted):

if file_format ==  ".npy":

    inst_map = pred[:,:,0]

    type_map = pred[:,:,1]

if file_format ==  ".mat":

    inst_map = pred['inst_map']

    type_map = pred['inst_type']



if(np.any(type_map==1)):

    result[i,:,:,0] = np.where(type_map == 1, inst_map, result[i,:,:,0])

if(np.any(type_map==2)):

    result[i,:,:,1] = np.where(type_map == 2, inst_map, result[i,:,:,1])

if(np.any(type_map==3)):

    result[i,:,:,2] = np.where(type_map == 3, inst_map, result[i,:,:,2])

if(np.any(type_map==4)):

    result[i,:,:,3] = np.where(type_map == 4, inst_map, result[i,:,:,3])

if(np.any(type_map==5)):

The error is caused by a shape mismatch in np.where as seen here:

a = np.random.randn(15, 1) > 0.
b = np.random.randn(256, 256)
c = np.random.randn(256, 256)
np.where(a, b, c)
# > operands could not be broadcast together with shapes (15,1) (256,256) (256,256) 

Check the docs of this call and make sure b and c are broadcastable to a.