cabbage972/GitChameleon-2.0 huggingface dataset:
Library: scipy==1.11.2 (Python 3.10, released 2023-08)

Problem: 
Complete the compute_lu_decomposition function that computes the lu decomposition of batched square matrices (batched in the first dimention), non specified parameters should use the default value

Starting code:
from scipy.linalg import lu
import numpy as np 
def compute_lu_decomposition(A: np.ndarray) -> tuple[np.ndarray,np.ndarray,np.ndarray]:
    # return p, l, u

Solution:

    return lu(A)

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]]])
p,l,u = compute_lu_decomposition(A)
assertion_value = np.allclose(np.stack([p,l,u],axis=1) ,np.stack([lu(A[i]) for i in range(A.shape[0])],axis=0))
assert assertion_value
Library: scipy==1.11.2 (Python 3.10, released 2023-08)

Problem: 
Complete the function that returns a lanczos windows, non specified parameters should use the default value

Starting code:
import scipy.signal.windows as windows
import numpy as np
def compute_lanczos_window(window_size:int)->np.ndarray:

Solution:

    return windows.lanczos(window_size)

Test:

window_size=31
window = compute_lanczos_window(window_size)
expect = np.array([
    3.89817183e-17, 7.09075143e-02, 1.49386494e-01, 2.33872321e-01,
    3.22568652e-01, 4.13496672e-01, 5.04551152e-01, 5.93561534e-01,
    6.78356039e-01, 7.56826729e-01, 8.26993343e-01, 8.87063793e-01,
    9.35489284e-01, 9.71012209e-01, 9.92705200e-01, 1.00000000e+00,
    9.92705200e-01, 9.71012209e-01, 9.35489284e-01, 8.87063793e-01,
    8.26993343e-01, 7.56826729e-01, 6.78356039e-01, 5.93561534e-01,
    5.04551152e-01, 4.13496672e-01, 3.22568652e-01, 2.33872321e-01,
    1.49386494e-01, 7.09075143e-02, 3.89817183e-17
])
assertion_value = np.allclose(window,expect)
assert assertion_value
Library: scipy==1.9.2 (Python 3.10, released 2022-10)

Problem: 
Complete the function that returns a lanczos windows, non specified parameters should use the default value

Starting code:
import scipy.signal.windows as windows
import numpy as np
def compute_lanczos_window(window_size:int)->np.ndarray:

Solution:

    window = 2*np.arange(window_size)/(window_size-1) - 1 
    window = np.sinc(window)
    window = window / np.max(window)
    return window 

Test:

window_size=31
window = compute_lanczos_window(window_size)
expect = np.array([
    3.89817183e-17, 7.09075143e-02, 1.49386494e-01, 2.33872321e-01,
    3.22568652e-01, 4.13496672e-01, 5.04551152e-01, 5.93561534e-01,
    6.78356039e-01, 7.56826729e-01, 8.26993343e-01, 8.87063793e-01,
    9.35489284e-01, 9.71012209e-01, 9.92705200e-01, 1.00000000e+00,
    9.92705200e-01, 9.71012209e-01, 9.35489284e-01, 8.87063793e-01,
    8.26993343e-01, 7.56826729e-01, 6.78356039e-01, 5.93561534e-01,
    5.04551152e-01, 4.13496672e-01, 3.22568652e-01, 2.33872321e-01,
    1.49386494e-01, 7.09075143e-02, 3.89817183e-17
])
assertion_value = np.allclose(window,expect)
assert assertion_value
Library: scipy==1.10.1 (Python 3.10, released 2023-02)

Problem: 
Complete the function that apply a 1D gaussian filter, non specified parameters should use the default value

Starting code:
from scipy.ndimage import gaussian_filter1d
import numpy as np
def apply_gaussian_filter1d(x:np.ndarray, radius:int, sigma:float)->np.ndarray:

Solution:

    return gaussian_filter1d(x, radius=radius, sigma=sigma)

Test:

np.random.seed(42)
x = np.random.rand(100)
radius = 10
sigma= np.pi
output = apply_gaussian_filter1d(x, radius=radius, sigma=sigma)
expect = np.array([
    0.56815745, 0.55427942, 0.53042419, 0.50274436, 0.47939431, 0.46608408,
    0.46527533, 0.4744513,  0.48749056, 0.49688273, 0.4972386,  0.48550617,
    0.46339406, 0.43606723, 0.40952566, 0.38910972, 0.37656404, 0.37165055,
    0.37174331, 0.37468009, 0.37962381, 0.38653222, 0.39495139, 0.40508619,
    0.41475306, 0.42135263, 0.423637,   0.42273663, 0.42245913, 0.42707435,
    0.43961646, 0.46012253, 0.48430625, 0.50544533, 0.51606669, 0.5127542,
    0.49612029, 0.47181487, 0.44642797, 0.42617826, 0.41556205, 0.41473155,
    0.42283456, 0.43706944, 0.4548513,  0.476166,   0.50121046, 0.53152392,
    0.56672268, 0.60382116, 0.63693437, 0.65767482, 0.65869746, 0.63622787,
    0.59180857, 0.53395824, 0.47319519, 0.42179978, 0.38691321, 0.37179661,
    0.37333425, 0.38479753, 0.40035159, 0.41614361, 0.43076203, 0.44494718,
    0.45937374, 0.47391018, 0.48731474, 0.49840656, 0.50731306, 0.51444675,
    0.52002105, 0.52266915, 0.52084841, 0.51247425, 0.49789513, 0.47962127,
    0.4608554,  0.44470093, 0.4319703,  0.42466571, 0.42407116, 0.43154786,
    0.44773618, 0.47128269, 0.49819701, 0.52370836, 0.54433314, 0.55848065,
    0.56652679, 0.56791146, 0.56167112, 0.54485643, 0.51513067, 0.47291521,
    0.42246471, 0.37170576, 0.3304751,  0.30701553
])
assertion_value = np.allclose(output,output)
assert assertion_value
Library: scipy==1.9.2 (Python 3.10, released 2022-10)

Problem: 
Complete the function that apply a 1D gaussian filter, non specified parameters should use the default value

Starting code:
from scipy.ndimage import gaussian_filter1d
import numpy as np
def apply_gaussian_filter1d(x:np.ndarray, radius:int, sigma:float)->np.ndarray:

Solution:

    return gaussian_filter1d(x, truncate = radius/sigma,sigma=sigma)

Test:

np.random.seed(42)
x = np.random.rand(100)
radius = 10
sigma= np.pi
output = apply_gaussian_filter1d(x, radius=radius, sigma=sigma)
expect = np.array([
    0.56815745, 0.55427942, 0.53042419, 0.50274436, 0.47939431, 0.46608408,
    0.46527533, 0.4744513,  0.48749056, 0.49688273, 0.4972386,  0.48550617,
    0.46339406, 0.43606723, 0.40952566, 0.38910972, 0.37656404, 0.37165055,
    0.37174331, 0.37468009, 0.37962381, 0.38653222, 0.39495139, 0.40508619,
    0.41475306, 0.42135263, 0.423637,   0.42273663, 0.42245913, 0.42707435,
    0.43961646, 0.46012253, 0.48430625, 0.50544533, 0.51606669, 0.5127542,
    0.49612029, 0.47181487, 0.44642797, 0.42617826, 0.41556205, 0.41473155,
    0.42283456, 0.43706944, 0.4548513,  0.476166,   0.50121046, 0.53152392,
    0.56672268, 0.60382116, 0.63693437, 0.65767482, 0.65869746, 0.63622787,
    0.59180857, 0.53395824, 0.47319519, 0.42179978, 0.38691321, 0.37179661,
    0.37333425, 0.38479753, 0.40035159, 0.41614361, 0.43076203, 0.44494718,
    0.45937374, 0.47391018, 0.48731474, 0.49840656, 0.50731306, 0.51444675,
    0.52002105, 0.52266915, 0.52084841, 0.51247425, 0.49789513, 0.47962127,
    0.4608554,  0.44470093, 0.4319703,  0.42466571, 0.42407116, 0.43154786,
    0.44773618, 0.47128269, 0.49819701, 0.52370836, 0.54433314, 0.55848065,
    0.56652679, 0.56791146, 0.56167112, 0.54485643, 0.51513067, 0.47291521,
    0.42246471, 0.37170576, 0.3304751,  0.30701553
])
assertion_value = np.allclose(output,output)
assert assertion_value
Library: scipy==1.11.2 (Python 3.10, released 2023-08)

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:

    return rank_filter(A,rank,size=size,axes=[1,2])

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
Library: scipy==1.11.2 (Python 3.10, released 2023-08)

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

Starting code:
from scipy.ndimage import median_filter
import numpy as np 
def apply_median_filter(A: np.ndarray,size:int) -> np.ndarray:

Solution:

    return median_filter(A,size=size,axes=[1,2])

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]]])
size=3
output = apply_median_filter(A,size=size)
assertion_value = np.allclose(output, np.stack([ median_filter(A[i], size=size) for i in range(A.shape[0])],axis=0))
assert assertion_value
Library: scipy==1.11.2 (Python 3.10, released 2023-08)

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

Starting code:
from scipy.ndimage import uniform_filter
import numpy as np 
def apply_uniform_filter(A: np.ndarray, size: int) -> np.ndarray:

Solution:

    return uniform_filter(A,size=size,axes=[1,2])

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]]])
size=3
output = apply_uniform_filter(A,size=size)
expect = np.array([
    [
        [0.53935158, 0.60597923, 0.52531988, 0.6400486,  0.55389319],
        [0.4618167,  0.58490121, 0.5862593,  0.68096102, 0.62637922],
        [0.2997042,  0.44301383, 0.51620539, 0.54122249, 0.48022706],
        [0.32287094, 0.38183581, 0.42015617, 0.55393411, 0.55672963],
        [0.43823881, 0.37027365, 0.25734465, 0.40653391, 0.43676824]
    ],
    [
        [0.64219576, 0.61810039, 0.59238323, 0.47523269, 0.28870856],
        [0.55556956, 0.63174782, 0.61502292, 0.56421916, 0.44228132],
        [0.5884824,  0.59521518, 0.54452428, 0.60285439, 0.60840439],
        [0.54582423, 0.48560024, 0.3840295,  0.43755765, 0.53590952],
        [0.62159479, 0.43195191, 0.29961636, 0.28979841, 0.41052592]
    ],
    [
        [0.70090615, 0.62187891, 0.49392997, 0.46120842, 0.31657062],
        [0.69062065, 0.59200365, 0.42676658, 0.38664908, 0.34123725],
        [0.64371953, 0.49929523, 0.40338435, 0.4323948,  0.56259273],
        [0.3653535,  0.3265107,  0.41749318, 0.53585902, 0.66816465],
        [0.23682579, 0.2139215,  0.45544829, 0.62939137, 0.81838701]
    ]
])
assertion_value = np.allclose(output, expect)
assert assertion_value
Library: scipy==1.11.2 (Python 3.10, released 2023-08)

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

Starting code:
from scipy.ndimage import maximum_filter
import numpy as np 
def apply_maximum_filter(A: np.ndarray, size: int) -> np.ndarray:
    

Solution:

    return maximum_filter(A,size=size,axes=[1,2])

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]]])
size=3
output = apply_maximum_filter(A,size=size)
expect = np.array([
    [
        [0.79004956, 0.93967961, 0.93967961, 0.93967961, 0.69554888],
        [0.79004956, 0.93967961, 0.93967961, 0.93967961, 0.93104606],
        [0.79004956, 0.89101424, 0.89101424, 0.93104606, 0.93104606],
        [0.91544553, 0.91544553, 0.89101424, 0.93104606, 0.93104606],
        [0.91544553, 0.91544553, 0.55219084, 0.7264364,  0.7264364 ]
    ],
    [
        [0.75093187, 0.90551488, 0.90551488, 0.90551488, 0.84842414],
        [0.75093187, 0.90551488, 0.90551488, 0.92857912, 0.92857912],
        [0.98004417, 0.98004417, 0.90551488, 0.92857912, 0.92857912],
        [0.98004417, 0.98004417, 0.88935511, 0.92857912, 0.92857912],
        [0.98004417, 0.98004417, 0.67144648, 0.77465223, 0.77465223]
    ],
    [
        [0.99945597, 0.99945597, 0.94112343, 0.92866297, 0.67511118],
        [0.99945597, 0.99945597, 0.94112343, 0.92866297, 0.67511118],
        [0.99945597, 0.99945597, 0.97632007, 0.97632007, 0.97632007],
        [0.5460935,  0.5460935,  0.97632007, 0.97632007, 0.97632007],
        [0.51531959, 0.51531959, 0.97632007, 0.97632007, 0.97632007]
    ]
])

assertion_value = np.allclose(output, expect)
assert assertion_value
Library: scipy==1.11.2 (Python 3.10, released 2023-08)

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

Starting code:
from scipy.ndimage import gaussian_filter
import numpy as np 
def apply_gaussian_filter(A: np.ndarray, sigma: float) -> np.ndarray:
    

Solution:

    return gaussian_filter(A,sigma=sigma,axes=[1,2])

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]]])
sigma=2
output = apply_gaussian_filter(A,sigma=sigma)
expect = np.array([
    [
        [0.51107853, 0.52434293, 0.5435481,  0.55983926, 0.56841324],
        [0.48836795, 0.50252599, 0.52348203, 0.54190047, 0.55197513],
        [0.4538848,  0.46817802, 0.49030855, 0.51105784, 0.52313636],
        [0.42268583, 0.43538067, 0.45646669, 0.47802514, 0.49150328],
        [0.40530094, 0.41608726, 0.43533884, 0.45656804, 0.47057292]
    ],
    [
        [0.58159932, 0.567709,   0.54222862, 0.51274141, 0.49237396],
        [0.56988096, 0.55678826, 0.53427875, 0.50995134, 0.49392329],
        [0.54914438, 0.53583943, 0.51580817, 0.49760273, 0.4872573 ],
        [0.52640569, 0.51103919, 0.49059125, 0.47570284, 0.46933531],
        [0.51143711, 0.4938774,  0.47171782, 0.45745161, 0.45266544]
    ],
    [
        [0.56163134, 0.53611524, 0.4985118,  0.46508331, 0.44632982],
        [0.53501922, 0.51740249, 0.49329637, 0.47430703, 0.46497321],
        [0.4887689,  0.48537733, 0.48514968, 0.49115186, 0.49783821],
        [0.43872375, 0.45125797, 0.47730807, 0.51021342, 0.53383157],
        [0.40596121, 0.42914707, 0.47257655, 0.523013,   0.55752451]
    ]
])
assertion_value = np.allclose(output, expect)
assert assertion_value
Library: flask==2.0.0 (Python 3.10, released 2021-05)
Additional dependencies: werkzeug==2.0.0

Problem: 
Complete the app_set_up function that set-up the app in such manner that the json encoding returns a sorted list
 when called with the eval function provided with the variable 
 num_set being a set of numbers, use other libraries if needed. Do not run the app in your code.

Starting code:
import flask

app = flask.Flask('test')
@app.route('/data')
def data(num_set):
    return flask.jsonify({'numbers': num_set})

def eval(app, data_fn, num_set):
    with app.test_request_context():
        response = data_fn(num_set)
        return response.get_data(as_text=False)

def app_set_up(app: flask.Flask) -> None: 
    

Solution:

    import json
    class MyCustomJSONHandler(json.JSONEncoder):
        def default(self, obj):
            if isinstance(obj, set):
                return sorted(list(obj))
            return super().default(obj)
    app.json_encoder = MyCustomJSONHandler


Test:

import json
app_set_up(app)
app2 = flask.Flask('test2')
@app2.route('/data2')
def data2(num_set):
    return flask.jsonify({'numbers': num_set})
class MyCustomJSONHandler2(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, set):
            return sorted(list(obj))
        return super().default(obj)

app2.json_encoder = MyCustomJSONHandler2
assertion_result = eval(app2, data2, {3, 1, 2, 6, 5, 4}) == eval(app, data, {3, 1, 2, 6, 5, 4})
assert assertion_result