Library: scipy==1.9.2 (Python 3.10, released 2022-10)

Problem: 
Complete the function that applies a rank filter on batched images (batched in the first dimention), non specified parameters should use the default value

Starting code:
from scipy.ndimage import rank_filter
import numpy as np 

def apply_rank_filter(A: np.ndarray,rank: int,size:int)->np.ndarray:

Solution:

    output = np.zeros(A.shape)
    for i in range(A.shape[0]):
        output[i] = rank_filter(A[i],rank,size=size)
    return output

Test:

A = np.array([[[7.81411439e-01, 1.12331105e-02, 9.39679607e-01, 6.42515536e-01,
         6.95548884e-01],
        [4.58001321e-01, 7.90049557e-01, 7.41113873e-01, 9.85894466e-03,
         4.53976568e-01],
        [2.24634401e-01, 4.26973301e-01, 8.91014236e-01, 8.23895514e-01,
         9.31046059e-01],
        [4.45855698e-02, 2.58723740e-02, 3.84879860e-01, 5.52190839e-01,
         8.30264909e-02],
        [9.15445530e-01, 8.36618255e-02, 4.39455188e-01, 1.53462390e-01,
         7.26436401e-01]],

       [[7.28031138e-01, 3.75117422e-01, 5.42310487e-01, 5.63557751e-01,
         2.57909701e-04],
        [7.50931873e-01, 6.15538706e-01, 9.05514875e-01, 8.48424138e-01,
         3.10902901e-01],
        [1.72613108e-01, 7.06317645e-01, 8.89355115e-01, 8.90701413e-02,
         9.28579120e-01],
        [9.80044173e-01, 1.67306937e-01, 1.69314197e-01, 5.09876755e-01,
         7.74652232e-01],
        [5.31016205e-01, 6.71446481e-01, 8.29882594e-02, 1.70589945e-01,
         3.23593050e-01]],

       [[8.38046468e-01, 7.96708042e-03, 9.28662972e-01, 6.75111182e-01,
         3.33247539e-02],
        [9.99455965e-01, 9.41123427e-01, 1.06977786e-01, 1.73786082e-01,
         5.95914076e-01],
        [5.46093501e-01, 4.99303483e-01, 4.60402210e-01, 4.75650259e-02,
         4.58097639e-01],
        [5.15319589e-01, 2.31310779e-01, 1.93670305e-01, 9.76320068e-01,
         8.78819966e-01],
        [1.09356481e-01, 2.16028113e-01, 1.67111833e-01, 9.65726787e-01,
         6.75017369e-01]]])
rank = 6
size=3
output = apply_rank_filter(A,rank,size=size)
expect = np.array([
    [
        [0.78141144, 0.79004956, 0.79004956, 0.74111387, 0.69554888],
        [0.78141144, 0.79004956, 0.82389551, 0.89101424, 0.82389551],
        [0.45800132, 0.74111387, 0.79004956, 0.82389551, 0.82389551],
        [0.4269733,  0.43945519, 0.55219084, 0.82389551, 0.82389551],
        [0.91544553, 0.43945519, 0.43945519, 0.55219084, 0.7264364 ]
    ],
    [
        [0.72803114, 0.72803114, 0.61553871, 0.56355775, 0.56355775],
        [0.72803114, 0.75093187, 0.84842414, 0.88935511, 0.84842414],
        [0.75093187, 0.88935511, 0.84842414, 0.88935511, 0.84842414],
        [0.70631765, 0.70631765, 0.67144648, 0.77465223, 0.77465223],
        [0.67144648, 0.67144648, 0.50987675, 0.32359305, 0.50987675]
    ],
    [
        [0.94112343, 0.92866297, 0.92866297, 0.67511118, 0.59591408],
        [0.94112343, 0.92866297, 0.67511118, 0.59591408, 0.59591408],
        [0.94112343, 0.5460935,  0.49930348, 0.59591408, 0.87881997],
        [0.51531959, 0.49930348, 0.49930348, 0.87881997, 0.87881997],
        [0.23131078, 0.21602811, 0.96572679, 0.96572679, 0.96572679]
    ]
])
assertion_value = np.allclose(output, expect)
assert assertion_value