python_version
stringclasses
3 values
library
stringclasses
26 values
version
stringlengths
1
6
problem
stringlengths
34
1.02k
starting_code
stringlengths
23
1.55k
example_id
stringlengths
1
3
test
stringlengths
66
5.96k
solution
stringlengths
7
9.39k
type_of_change
stringclasses
21 values
name_of_class_or_func
stringlengths
0
63
additional_dependencies
stringclasses
31 values
docs
listlengths
1
3
functional
unknown
webdev
unknown
solution_api_call
bool
1 class
api_calls
listlengths
0
47
release_date
stringdate
2014-08-01 00:00:00
2024-01-01 00:00:00
extra_dependencies
stringclasses
3 values
3.10
django
4.0.0
Complete the function save_existing. Do not run the app in your code.
from django.conf import settings from django.forms.models import BaseModelFormSet from django.forms.renderers import get_default_renderer from django.forms import Form settings.configure() def save_existing(formset: BaseModelFormSet, form : Form, obj:str) -> None:
101
class DummyForm: def save(self, commit=True): return 'dummy_instance_value_result' class MyFormSet(BaseModelFormSet): def __init__(self, *args, **kwargs): self.renderer = get_default_renderer() super().__init__(*args, **kwargs) fs5 = MyFormSet(queryset=[]) result = save_existing(forms...
return formset.save_existing(form=form,instance=obj)
argument or attribute change
BaseModelFormSet.save_existing
[ "https://docs.djangoproject.com/en/5.1/topics/forms/", "https://docs.djangoproject.com/en/5.2/topics/settings/", "https://docs.djangoproject.com/en/5.2/releases/4.0/" ]
1
1
true
[ "formset.save_existing" ]
2021-12
null
3.10
django
5.0.0
Complete the function save_existing. Do not run the app in your code.
from django.conf import settings from django.forms.models import BaseModelFormSet from django.forms.renderers import get_default_renderer from django.forms import Form settings.configure() def save_existing(formset: BaseModelFormSet, form : Form, instance:str) -> None:
102
class DummyForm: def save(self, commit=True): return 'dummy_instance_value_result' class MyFormSet(BaseModelFormSet): def __init__(self, *args, **kwargs): self.renderer = get_default_renderer() super().__init__(*args, **kwargs) fs5 = MyFormSet(queryset=[]) result = save_existing(formse...
return formset.save_existing(form=form,obj=instance)
argument or attribute change
Template.render
[ "https://docs.djangoproject.com/en/5.1/topics/forms/", "https://docs.djangoproject.com/en/5.2/topics/settings/", "https://docs.djangoproject.com/en/5.2/releases/5.0/" ]
1
1
true
[ "formset.save_existing" ]
2023-12
null
3.10
django
5.0.0
Complete the get_template_string function so that the template_string variable form the html string provided in comments, making the best use of the templates for form field rendering. Do not run the app in your code.
import django from django.conf import settings from django import forms from django.template import Template, Context settings.configure( TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', }, ], ) django.setup() def render_output(template_string...
103
template_string= get_template_string() rendered_output = render_output(template_string) def normalize_html(html): # Remove all whitespace and standardize quotation marks to single quotes normalized = ''.join(html.split()) return normalized template_string_django_4 = ''' <form> <div> {{ form.name.lab...
return ''' <form> <div> {{ form.name.as_field_group }} </div> </form> '''
other library or new feature
Template.render
[ "https://docs.djangoproject.com/en/5.0/ref/templates/api/" ]
1
1
true
[]
2023-12
null
3.10
django
4.0.0
Complete the get_template_string function so that the template_string variable form the html string provided in comments, making the best use of the templates for form field rendering. Do not run the app in your code.
import django from django.conf import settings from django import forms from django.template import Template, Context settings.configure( TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', }, ], ) django.setup() def render_output(template_string...
104
template_string = get_template_string() rendered_output = render_output(template_string) def normalize_html(html): # Remove all whitespace and standardize quotation marks to single quotes normalized = ''.join(html.split()) return normalized template_string_django_4 = ''' <form> <div> {{ form.name.l...
return ''' <form> <div> {{ form.name.label_tag }} {% if form.name.help_text %} <div class="helptext" id="{{ form.name.auto_id }}_helptext"> {{ form.name.help_text|safe }} </div> {% endif %} {{ form.name.errors }} {{ form.name }} </div> </form> '''
other library or new feature
BoundField.as_field_group()
[ "https://docs.djangoproject.com/en/4.0/ref/templates/api/" ]
1
1
true
[]
2021-12
null
3.10
django
4.0.0
Create Square model with a side field and an area field that is calculated as the square of the side. Do not run the app in your code.
import django from django.conf import settings from django.db import models, connection from django.db.models import F settings.configure( DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}}, ) django.setup() def display_side_and_area(square): return square.side, square.area ...
105
with connection.schema_editor() as schema_editor: schema_editor.create_model(Square) square = create_square(side=5) correct_result = (5, 25) assert display_side_and_area(square) == correct_result
models.BigIntegerField(editable=False) def save(self, *args, **kwargs): # Compute the area before saving. self.area = self.side * self.side super().save(*args, **kwargs)
other library or new feature
BoundField.models.GeneratedField()
[ "https://docs.djangoproject.com/en/4.0/ref/models/fields/" ]
0
1
true
[ "models.BigIntegerField", "super", "save" ]
2021-12
null
3.10
django
5.0.0
Create Square model with a side field and an area field that is calculated as the square of the side. Do not run the app in your code.
import django from django.conf import settings from django.db import models, connection from django.db.models import F settings.configure( DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}}, ) django.setup() def display_side_and_area(square): return square.side, square.area ...
106
with connection.schema_editor() as schema_editor: schema_editor.create_model(Square) square = create_square(side=5) correct_result = (5, 25) assert display_side_and_area(square) == correct_result
models.GeneratedField( expression=F('side') * F('side'), output_field=models.BigIntegerField(), db_persist=True, )
other library or new feature
BoundField.models.GeneratedField()
[ "https://docs.djangoproject.com/en/5.0/ref/models/fields/" ]
0
1
true
[ "models.BigIntegerField", "django.db.models.F", "models.GeneratedField" ]
2023-12
null
3.10
django
5.0.0
Create a model based on the given color choices. Do not run the app in your code.
import django from django.conf import settings from django.db import models settings.configure() django.setup() color = models.TextChoices('Color', 'RED GREEN BLUE') class MyModel(models.Model): class Meta: app_label = 'myapp' color = models.CharField(max_length=5,
107
field_choices = list(MyModel._meta.get_field('color').choices) expected_choices = [('RED', 'Red'), ('GREEN', 'Green'), ('BLUE', 'Blue')] assert field_choices == expected_choices
choices=color)
argument or attribute change
Field.choices
[ "https://docs.djangoproject.com/en/5.0/ref/models/fields/" ]
0
1
true
[]
2023-12
null
3.10
django
4.0.0
Create a model based on the given color choices. Do not run the app in your code.
import django from django.conf import settings from django.db import models settings.configure() django.setup() color = models.TextChoices('Color', 'RED GREEN BLUE') class MyModel(models.Model): class Meta: app_label = 'myapp' color = models.CharField(max_length=5,
108
field_choices = MyModel._meta.get_field('color').choices expected_choices = [('RED', 'Red'), ('GREEN', 'Green'), ('BLUE', 'Blue')] assert field_choices == expected_choices
choices=color.choices)
argument or attribute change
Field.choices
[ "https://docs.djangoproject.com/en/4.0/ref/models/fields/" ]
0
1
true
[]
2021-12
null
3.10
scipy
1.7.3
complete the function that computes the weigthed Minkowski distance between two 1-D arrays, u and v, based on a 1D weigth vector, w.
from scipy.spatial import distance import numpy as np def compute_wminkowski(u:np.ndarray, v:np.ndarray, p:int, w:np.ndarray)->np.ndarray:
109
u = np.asarray([11,12,13,14,15]) v = np.asarray([1,2,3,4,5]) w = np.asarray([0.1,0.3,0.15,0.25,0.2]) output = compute_wminkowski(u,v,p=3,w=w) assertion_value = np.allclose(output, 3.8029524607613916) assert assertion_value
return distance.wminkowski(u,v,p=p,w=w)
name change
distance.wminkowski
[ "https://docs.scipy.org/doc/scipy-1.7.1/reference/reference/spatial.distance.html" ]
1
0
true
[ "scipy.spatial.distance.wminkowski" ]
2021-11
null
3.10
scipy
1.9.2
complete the function that computes the weigthed Minkowski distance between two 1-D arrays, u and v, based on a 1D weigth vector, w.
from scipy.spatial import distance import numpy as np def compute_wminkowski(u:np.ndarray, v:np.ndarray, p:int, w:np.ndarray)->np.ndarray:
110
u = np.asarray([11,12,13,14,15]) v = np.asarray([1,2,3,4,5]) w = np.asarray([0.1,0.3,0.15,0.25,0.2]) output = compute_wminkowski(u,v,p=3,w=w) assertion_value = np.allclose(output, 9.999999999999998) assert assertion_value
return distance.minkowski(u,v,p=p,w=w)
name change
distance.minkowski
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/spatial.distance.html" ]
1
0
true
[ "scipy.spatial.distance.minkowski" ]
2022-10
null
3.10
scipy
1.8.1
Complete the function that computes the matrix exponential of batched matrices, non specified parameters should use the default value
from scipy import linalg import numpy as np def compute_matrix_exponential(A: np.ndarray) -> np.ndarray:
111
A = np.array([[[0.25264461, 0.67582554, 0.90718149, 0.65460219], [0.58271792, 0.4600052 , 0.22265374, 0.98210688], [0.92575218, 0.66167048, 0.81779481, 0.15405207], [0.00820708, 0.7702345 , 0.4285001 , 0.87567275]], [[0.48362533, 0.10258182, 0.58965127, 0.89320413], [0.11275151, ...
return np.stack([linalg.expm(A[i]) for i in range(A.shape[0])],axis=0)
argument or attribute change
linalg.expm
[ "https://docs.scipy.org/doc/scipy-1.8.1/reference/generated/scipy.linalg.expm.html" ]
1
0
true
[ "range", "numpy.stack", "scipy.linalg.expm" ]
2022-05
null
3.10
scipy
1.9.2
Complete the function that compute the matrix exponential of batched matrices, non specified parameters should use the default value
from scipy import linalg import numpy as np def compute_matrix_exponential(A: np.ndarray) -> np.ndarray:
112
A = np.array([[[0.25264461, 0.67582554, 0.90718149, 0.65460219], [0.58271792, 0.4600052 , 0.22265374, 0.98210688], [0.92575218, 0.66167048, 0.81779481, 0.15405207], [0.00820708, 0.7702345 , 0.4285001 , 0.87567275]], [[0.48362533, 0.10258182, 0.58965127, 0.89320413], [0.11275151, ...
return linalg.expm(A)
argument or attribute change
linalg.expm
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/generated/scipy.linalg.expm.html#scipy.linalg.expm" ]
1
0
true
[ "scipy.linalg.expm" ]
2022-10
null
3.10
scipy
1.8.1
Complete the function that combines the p values from various independent tests stored in a 1D array using pearson method, make sure that higher values of the statistic now correspond to lower p-values, non specified parameters should use the default value
from scipy import stats import numpy as np def combine_pvalues(A: np.ndarray) -> tuple[float, float]:
113
A = np.array([0.01995382, 0.1906752 , 0.71157923, 0.44477942, 0.4535412 , 0.67556953, 0.11174941, 0.85494112, 0.33214635, 0.19103228]) output = combine_pvalues(A) assertion_value = np.allclose(np.asarray(output),np.asarray([-stats.combine_pvalues(1-A,'fisher')[0],(1-stats.combine_pvalues(1-A,'fisher')[1])])) ...
output = stats.combine_pvalues(A,'pearson') return (-output[0], 1-output[1])
output change
stats.combine_pvalues
[ "https://docs.scipy.org/doc/scipy-1.8.1/reference/generated/scipy.stats.combine_pvalues.html" ]
1
0
true
[ "return", "scipy.stats.combine_pvalues" ]
2022-05
null
3.10
scipy
1.9.2
Complete the function that combines the p values from various independent tests stored in a 1D array using pearson method, make sure that higher values of the statistic now correspond to lower p-values, non specified parameters should use the default value
from scipy import stats import numpy as np def combine_pvalues(A: np.ndarray) -> tuple[float, float]:
114
A = np.array([0.01995382, 0.1906752 , 0.71157923, 0.44477942, 0.4535412 , 0.67556953, 0.11174941, 0.85494112, 0.33214635, 0.19103228]) output = combine_pvalues(A) expect = np.array([-12.91643003, 0.11905922]) assertion_value = np.allclose(np.asarray(output),expect) assert assertion_value
return stats.combine_pvalues(A,'pearson')
output change
stats.combine_pvalues
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/generated/scipy.stats.combine_pvalues.html" ]
1
0
true
[ "scipy.stats.combine_pvalues" ]
2022-10
null
3.10
scipy
1.8.1
Write a function that computes the matrix exponential of a sparse array A, non specified parameters should use the default value
from scipy import sparse,linalg import numpy as np def compute_matrix_exponential(A:sparse.lil_matrix)->sparse.lil_matrix:
115
A = sparse.lil_matrix((3, 3)) A[0, 0] = 4 A[1, 1] = 5 A[1, 2] = 6 output = compute_matrix_exponential(A) expect = np.array([ [54.59815003, 0., 0. ], [ 0., 148.4131591, 176.89579092], [ 0., 0., 1. ] ]) assertion_value = np.allclose(output.todense(), expect...
return linalg.expm(A)
name change
linalg
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/generated/scipy.sparse.linalg.expm.html" ]
1
0
true
[ "linalg.expm" ]
2022-05
null
3.10
scipy
1.9.2
Write a function that computes the matrix exponential of a sparse array A, non specified parameters should use the default value
from scipy import sparse,linalg import numpy as np def compute_matrix_exponential(A: sparse.lil_matrix)->sparse.lil_matrix:
116
A = sparse.lil_matrix((3, 3)) A[0, 0] = 4 A[1, 1] = 5 A[1, 2] = 6 output = compute_matrix_exponential(A) expect = np.array([ [54.59815003, 0., 0. ], [ 0., 148.4131591, 176.89579092], [ 0., 0., 1. ] ]) assertion_value = np.allclose(output.todense(), expect...
return sparse.linalg.expm(A)
name change
linalg
[ "https://docs.scipy.org/doc/scipy-1.8.1/reference/generated/scipy.sparse.linalg.expm.html" ]
1
0
true
[ "sparse.linalg.expm" ]
2022-10
null
3.10
scipy
1.8.1
Write a function that computes the circular variance: 1-R, where R is the mean resultant vector.
from scipy import stats import numpy as np def compute_circular_variance(a: np.ndarray)-> float:
117
a = np.array([0, 2*np.pi/3, 5*np.pi/3]) output = compute_circular_variance(a) expect = 0.6666666666666665 assertion_value = np.allclose(output,expect) assert assertion_value
return 1-np.abs(np.mean(np.exp(1j*a)))
output change
stats.circvar
[ "https://docs.scipy.org/doc/scipy-1.8.1/reference/generated/scipy.stats.circvar.html" ]
1
0
true
[ "numpy.mean", "numpy.exp", "numpy.abs" ]
2022-05
null
3.10
scipy
1.9.2
Write a function that computes the circular variance: 1-R, where R is the mean resultant vector.
from scipy import stats import numpy as np def compute_circular_variance(a: np.ndarray)-> float:
118
a = np.array([0, 2*np.pi/3, 5*np.pi/3]) output = compute_circular_variance(a) expect = 0.6666666666666665 assertion_value = np.allclose(output,expect) assert assertion_value
return stats.circvar(a)
output change
stats.circvar
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/generated/scipy.stats.circvar.html" ]
1
0
true
[ "scipy.stats.circvar" ]
2022-10
null
3.10
scipy
1.11.2
Complete the compute_moment function that computes the n-th moment of a distribution dist.
from scipy.stats import rv_continuous def compute_moment(dist : rv_continuous, n: int) -> float:
119
from scipy.stats import norm import numpy as np dist = norm(15, 10) n=5 output = compute_moment(dist, n=n) expect = 6384375.000000001 assertion_value = np.allclose(output,expect) assert assertion_value
return dist.moment(order=n)
argument or attribute change
rv_continuous.momentr
[ "https://docs.scipy.org/doc/scipy-1.11.0/reference/generated/scipy.stats.rv_continuous.moment.html" ]
1
0
true
[ "dist.moment" ]
2023-08
null
3.10
scipy
1.9.2
Complete the compute_moment function that computes the n-th moment of a distribution dist.
from scipy.stats import rv_continuous def compute_moment(dist : rv_continuous, n: int) -> float:
120
from scipy.stats import norm import numpy as np dist = norm(15, 10) n=5 output = compute_moment(dist, n=n) expect = 6384375.000000001 assertion_value = np.allclose(output,expect) assert assertion_value
return dist.moment(n=n)
argument or attribute change
rv_continuous.moment
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/generated/scipy.stats.rv_continuous.moment.html" ]
1
0
true
[ "dist.moment" ]
2022-10
null
3.10
scipy
1.9.2
Write a function that computes the determinant of batched matrices (batched in the first dimention), non specified parameters should use the default value
from scipy.linalg import det import numpy as np def compute_determinant(A: np.ndarray) -> np.ndarray:
121
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.4585...
output = np.zeros(A.shape[0]) for i in range(A.shape[0]): output[i] = det(A[i]) return output
argument or attribute change
scipy.linalg.det
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/generated/scipy.linalg.det.html" ]
1
0
true
[ "range", "numpy.zeros", "scipy.linalg.det" ]
2022-10
null
3.10
scipy
1.11.2
Write a function that computes the determinant of batched matrices (batched in the first dimention), non specified parameters should use the default value
from scipy.linalg import det import numpy as np def compute_determinant(A: np.ndarray) -> np.ndarray:
122
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.4585...
return det(A)
argument or attribute change
scipy.linalg.det
[ "https://docs.scipy.org/doc/scipy-1.11.0/reference/generated/scipy.linalg.det.html" ]
1
0
true
[ "scipy.linalg.det" ]
2023-08
null
3.10
scipy
1.9.2
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
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
123
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.4585...
p,l,u = [np.zeros(A.shape) for i in range(3)] for i in range(A.shape[0]): p[i],l[i],u[i] = lu(A[i]) return p, l, u
argument or attribute change
scipy.linalg.lu
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/generated/scipy.linalg.lu.html" ]
1
0
true
[ "range", "scipy.linalg.lu", "numpy.zeros" ]
2022-10
null
3.10
scipy
1.11.2
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
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
124
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.4585...
return lu(A)
argument or attribute change
scipy.linalg.lu
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/generated/scipy.linalg.lu.html" ]
1
0
true
[ "scipy.linalg.lu" ]
2023-08
null
3.10
scipy
1.11.2
Complete the function that returns a lanczos windows, non specified parameters should use the default value
import scipy.signal.windows as windows import numpy as np def compute_lanczos_window(window_size:int)->np.ndarray:
125
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,...
return windows.lanczos(window_size)
other library or new feature
signal.windows.lanczos
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/generated/scipy.signal.windows.lanczos.html" ]
1
0
true
[ "scipy.signal.windows.lanczos" ]
2023-08
null
3.10
scipy
1.9.2
Complete the function that returns a lanczos windows, non specified parameters should use the default value
import scipy.signal.windows as windows import numpy as np def compute_lanczos_window(window_size:int)->np.ndarray:
126
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,...
window = 2*np.arange(window_size)/(window_size-1) - 1 window = np.sinc(window) window = window / np.max(window) return window
other library or new feature
signal.windows.lanczos
[ "https://numpy.org/doc/1.20/reference/generated/numpy.sinc.html" ]
1
0
true
[ "numpy.sinc", "numpy.max", "numpy.arange" ]
2022-10
null
3.10
scipy
1.10.1
Complete the function that apply a 1D gaussian filter, non specified parameters should use the default value
from scipy.ndimage import gaussian_filter1d import numpy as np def apply_gaussian_filter1d(x:np.ndarray, radius:int, sigma:float)->np.ndarray:
127
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,...
return gaussian_filter1d(x, radius=radius, sigma=sigma)
argument or attribute change
ndimage.gaussian_filter1d
[ "https://docs.scipy.org/doc/scipy-1.10.1/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.gaussian_filter1d" ]
2023-02
null
3.10
scipy
1.9.2
Complete the function that apply a 1D gaussian filter, non specified parameters should use the default value
from scipy.ndimage import gaussian_filter1d import numpy as np def apply_gaussian_filter1d(x:np.ndarray, radius:int, sigma:float)->np.ndarray:
128
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,...
return gaussian_filter1d(x, truncate = radius/sigma,sigma=sigma)
argument or attribute change
ndimage.gaussian_filter1d
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.gaussian_filter1d" ]
2022-10
null
3.10
scipy
1.11.2
Complete the function that applies a rank filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import rank_filter import numpy as np def apply_rank_filter(A: np.ndarray,rank: int,size:int)->np.ndarray:
129
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.4585...
return rank_filter(A,rank,size=size,axes=[1,2])
argument or attribute change
scipy.ndimage.rank_filter
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.rank_filter" ]
2023-08
null
3.10
scipy
1.9.2
Complete the function that applies a rank filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import rank_filter import numpy as np def apply_rank_filter(A: np.ndarray,rank: int,size:int)->np.ndarray:
130
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.4585...
output = np.zeros(A.shape) for i in range(A.shape[0]): output[i] = rank_filter(A[i],rank,size=size) return output
argument or attribute change
scipy.ndimage.rank_filter
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/ndimage.html" ]
1
0
true
[ "range", "numpy.zeros", "scipy.ndimage.rank_filter" ]
2022-10
null
3.10
scipy
1.11.2
Complete the function that applies a percentile filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import percentile_filter import numpy as np def apply_percentile_filter(A: np.ndarray, percentile: int | float,size:int)->np.ndarray:
131
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.4585...
return percentile_filter(A,percentile=percentile,size=size,axes=[1,2])
argument or attribute change
scipy.ndimage.percentile_filter
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.percentile_filter" ]
2023-08
null
3.10
scipy
1.9.2
Complete the function that applies a percentile filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import percentile_filter import numpy as np def apply_percentile_filter(A: np.ndarray, percentile: int | float,size:int)->np.ndarray:
132
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.4585...
output = np.zeros(A.shape) for i in range(A.shape[0]): output[i] = percentile_filter(A[i],percentile=percentile,size=size) return output
argument or attribute change
scipy.ndimage.percentile_filter
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/ndimage.html" ]
1
0
true
[ "range", "numpy.zeros", "scipy.ndimage.percentile_filter" ]
2022-10
null
3.10
scipy
1.11.2
Complete the function that applies a median filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import median_filter import numpy as np def apply_median_filter(A: np.ndarray,size:int) -> np.ndarray:
133
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.4585...
return median_filter(A,size=size,axes=[1,2])
argument or attribute change
scipy.ndimage.median_filter
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.median_filter" ]
2023-08
null
3.10
scipy
1.9.2
Complete the function that applies a median filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import median_filter import numpy as np def apply_median_filter(A: np.ndarray, size:int) -> np.ndarray:
134
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.4585...
output = np.zeros(A.shape) for i in range(A.shape[0]): output[i] = median_filter(A[i], size=size) return output
argument or attribute change
scipy.ndimage.median_filter
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/ndimage.html" ]
1
0
true
[ "range", "scipy.ndimage.median_filter", "numpy.zeros" ]
2022-10
null
3.10
scipy
1.11.2
Complete the function that applies a uniform filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import uniform_filter import numpy as np def apply_uniform_filter(A: np.ndarray, size: int) -> np.ndarray:
135
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.4585...
return uniform_filter(A,size=size,axes=[1,2])
argument or attribute change
scipy.ndimage.uniform_filter
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.uniform_filter" ]
2023-08
null
3.10
scipy
1.9.2
Complete the function that applies a uniform filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import uniform_filter import numpy as np def apply_uniform_filter(A: np.ndarray, size: int) -> np.ndarray:
136
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.4585...
output = np.zeros(A.shape) for i in range(A.shape[0]): output[i] = uniform_filter(A[i], size=size) return output
argument or attribute change
scipy.ndimage.uniform_filter
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/ndimage.html" ]
1
0
true
[ "range", "numpy.zeros", "scipy.ndimage.uniform_filter" ]
2022-10
null
3.10
scipy
1.11.2
Complete the function that applies a minimum filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import minimum_filter import numpy as np def apply_minimum_filter(A: np.ndarray, size: int) -> np.ndarray:
137
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.4585...
return minimum_filter(A,size=size,axes=[1,2])
argument or attribute change
scipy.ndimage.minimum_filter
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.minimum_filter" ]
2023-08
null
3.10
scipy
1.9.2
Complete the function that applies a minimum filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import minimum_filter import numpy as np def apply_minimum_filter(A: np.ndarray, size: int) -> np.ndarray:
138
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.4585...
output = np.zeros(A.shape) for i in range(A.shape[0]): output[i] = minimum_filter(A[i], size=size) return output
argument or attribute change
scipy.ndimage.minimum_filter
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/ndimage.html" ]
1
0
true
[ "range", "scipy.ndimage.minimum_filter", "numpy.zeros" ]
2022-10
null
3.10
scipy
1.11.2
Complete the function that applies a maximum filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import maximum_filter import numpy as np def apply_maximum_filter(A: np.ndarray, size: int) -> np.ndarray:
139
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.4585...
return maximum_filter(A,size=size,axes=[1,2])
argument or attribute change
scipy.ndimage.maximum_filter
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.maximum_filter" ]
2023-08
null
3.10
scipy
1.9.2
Complete the function that applies a maximum filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import maximum_filter import numpy as np def apply_maximum_filter(A: np.ndarray, size: int) -> np.ndarray:
140
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.4585...
output = np.zeros(A.shape) for i in range(A.shape[0]): output[i] = maximum_filter(A[i], size=size) return output
argument or attribute change
scipy.ndimage.maximum_filter
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/ndimage.html" ]
1
0
true
[ "range", "numpy.zeros", "scipy.ndimage.maximum_filter" ]
2022-10
null
3.10
scipy
1.11.2
Complete the function that applies a gaussian filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import gaussian_filter import numpy as np def apply_gaussian_filter(A: np.ndarray, sigma: float) -> np.ndarray:
141
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.4585...
return gaussian_filter(A,sigma=sigma,axes=[1,2])
argument or attribute change
scipy.ndimage.gaussian_filter
[ "https://docs.scipy.org/doc/scipy-1.11.1/reference/ndimage.html" ]
1
0
true
[ "scipy.ndimage.gaussian_filter" ]
2023-08
null
3.10
scipy
1.9.2
Complete the function that applies a gaussian filter on batched images (batched in the first dimention), non specified parameters should use the default value
from scipy.ndimage import gaussian_filter import numpy as np def apply_gaussian_filter(A: np.ndarray, sigma: float) -> np.ndarray:
142
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.4585...
output = np.zeros(A.shape) for i in range(A.shape[0]): output[i] = gaussian_filter(A[i],sigma=sigma) return output
argument or attribute change
scipy.ndimage.gaussian_filter
[ "https://docs.scipy.org/doc/scipy-1.9.2/reference/ndimage.html" ]
1
0
true
[ "range", "numpy.zeros", "scipy.ndimage.gaussian_filter" ]
2022-10
null
3.10
flask
2.0.0
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.
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) -> No...
143
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...
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
argument or attribute change
app.json_encoder
werkzeug==2.0.0
[ "https://tedboy.github.io/flask/interface_api.json_support.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "default", "isinstance", "sorted", "super", "list", "MyCustomJSONHandler" ]
2021-05
null
3.10
flask
3.0.0
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.
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=True) def app_set_up(app: flask.Flask) -> None...
144
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(flask.json.provider.DefaultJSONProvider): def default(self, obj): if isinstance(obj, set): return sorted(list(obj)) ...
class MyCustomJSONHandler(flask.json.provider.DefaultJSONProvider): def default(self, obj): if isinstance(obj, set): return sorted(list(obj)) return super().default(obj) app.json_provider_class = MyCustomJSONHandler app.json = app.json_provider_class(app)
argument or attribute change
app.json_encoder
[ "https://tedboy.github.io/flask/interface_api.json_support.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "default", "isinstance", "sorted", "super", "app.json_provider_class", "list", "MyCustomJSONHandler" ]
2023-09
null
3.10
flask
2.0.0
Complete the download definition to download the data in the variable attachment_filename. Do not run the app in your code.
from flask import Flask, send_file from io import BytesIO app1 = Flask(__name__) def get_content_disp(app, download_fn): with app.test_request_context(): response = download_fn() content_disp = response.headers.get('Content-Disposition') return content_disp @app1.route('/download') def download()...
145
content_disp = get_content_disp(app1, download) assertion_result = 'filename=hello.txt' in content_disp assert assertion_result
attachment_filename=attachment_filename)
argument or attribute change
flask.send_file
werkzeug==2.0.0
[ "https://tedboy.github.io/flask/generated/flask.send_file.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
0
1
true
[]
2021-05
null
3.10
flask
3.0.0
Complete the download definition to download the data in the variable attachment_filename. Do not run the app in your code.
from flask import Flask, send_file from io import BytesIO app1 = Flask(__name__) def get_content_disp(app, download_fn): with app.test_request_context(): response = download_fn() content_disp = response.headers.get('Content-Disposition') return content_disp @app1.route('/download') def download()...
146
content_disp = get_content_disp(app1, download) assertion_result = 'filename=hello.txt' in content_disp assert assertion_result
download_name=attachment_filename)
argument or attribute change
flask.send_file
[ "https://tedboy.github.io/flask/generated/flask.send_file.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
0
1
true
[]
2023-09
null
3.10
flask
2.0.1
Implement the function to load the JSON file to config the Flask app. Do not run the app in your code.
import json import tempfile from flask import Flask config_data = {'DEBUG': True, 'SECRET_KEY': 'secret'} with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.json') as tmp: json.dump(config_data, tmp) tmp.flush() config_file = tmp.name app = Flask(__name__) def load_config(config_file: str...
147
load_config(config_file) assertion_result= app.config['DEBUG'] is True and app.config['SECRET_KEY'] == 'secret' assert assertion_result
app.config.from_json(config_file)
name change
Flask.config.from_json
werkzeug==2.0.0
[ "https://flask.palletsprojects.com/en/stable/config/", "https://flask.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "app.config.from_json" ]
2021-05
null
3.10
flask
3.0.0
Load the json file to config the Flask app. Do not run the app in your code.
import json import tempfile from flask import Flask config_data = {'DEBUG': True, 'SECRET_KEY': 'secret'} with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.json') as tmp: json.dump(config_data, tmp) tmp.flush() config_file = tmp.name app = Flask(__name__) def load_config(config_file: str...
148
load_config(config_file) assertion_result= app.config['DEBUG'] is True and app.config['SECRET_KEY'] == 'secret' assert assertion_result
app.config.from_file(config_file, load=json.load)
name change
Flask.config.from_file
[ "https://flask.palletsprojects.com/en/stable/config/", "https://flask.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "app.config.from_file" ]
2023-09
null
3.10
flask
2.0.1
Complete the safe_join_fail_404 to safely join the path and the subpath, use other libraries if needed. Do not run the app in your code.
import flask import werkzeug error404 = werkzeug.exceptions.NotFound def safe_join_fail_404(base_path: str, sub_path: str) -> str: # Attempt to join the base path and sub path. # If the joined path is outside the base path, raise a 404 error.
149
base_path = '/var/www/myapp' sub_path = '../secret.txt' try : joined = safe_join_fail_404(base_path, sub_path) except werkzeug.exceptions.NotFound as e: assertion_result = True else: assertion_result = False assert assertion_result base_path = '/var/www/myapp' sub_path = 'secret.txt' joined = safe_join_...
joined = flask.safe_join(base_path, sub_path) return joined
name change
flask.safe_join
werkzeug==2.0.0
[ "https://tedboy.github.io/flask/generated/flask.safe_join.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "flask.safe_join" ]
2021-05
null
3.10
flask
3.0.0
Complete the safe_join_fail_404 to safely join the path and the subpath, use other libraries if needed. Do not run the app in your code.
import flask import werkzeug error404 = werkzeug.exceptions.NotFound def safe_join_fail_404(base_path: str, sub_path: str) -> str: # Attempt to join the base path and sub path. # If the joined path is outside the base path, raise a 404 error.
150
base_path = '/var/www/myapp' sub_path = '../secret.txt' try : joined = safe_join_fail_404(base_path, sub_path) except werkzeug.exceptions.NotFound as e: assertion_result = True else: assertion_result = False assert assertion_result base_path = '/var/www/myapp' sub_path = 'secret.txt' joined = safe_join_...
joined = werkzeug.utils.safe_join(base_path, sub_path) if joined is None: raise error404 return joined
name change
flask.safe_join
[ "https://werkzeug.palletsprojects.com/en/stable/utils/", "https://flask.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "werkzeug.utils.safe_join" ]
2023-09
null
3.10
flask
2.0.1
Complete the function convert_timedelta_to_seconds, use other libraries if needed. Do not run the app in your code.
import flask import datetime def convert_timedelta_to_seconds(td: datetime.timedelta) -> int:
151
import datetime td = datetime.timedelta(hours=2, minutes=30,microseconds=1) assertion_results = convert_timedelta_to_seconds(td)==9000 assert assertion_results
return flask.helpers.total_seconds(td)
name change
helpers.total_seconds
werkzeug==2.0.0
[ "https://flask.palletsprojects.com/en/stable/api/", "https://flask.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "flask.helpers.total_seconds" ]
2021-05
null
3.10
flask
3.0.0
Complete the function convert_timedelta_to_seconds, use other libraries if needed. Do not run the app in your code.
import flask import datetime def convert_timedelta_to_seconds(td: datetime.timedelta):
152
import datetime td = datetime.timedelta(hours=2, minutes=30,microseconds=1) assertion_results = convert_timedelta_to_seconds(td)==9000.000001 assert assertion_results
return td.total_seconds()
name change
helpers.total_seconds
[ "https://flask.palletsprojects.com/en/stable/api/", "https://flask.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "td.total_seconds" ]
2023-09
null
3.10
jinja2
2.11
Implement the solution function to return a custom filter. This filter should: accept the context and a parameter name, retrieve a variable prefix from the context (defaulting to 'Hello' if not provided), return a greeting message combining the prefix and the name. Do not run the app in your code.
import jinja2 from jinja2.runtime import Context from typing import Callable def setup_environment(filtername: str, filter: Callable[[Context, str], str]) -> jinja2.Environment: env = jinja2.Environment() env.filters[filtername] = filter return env def solution() -> Callable[[Context, str], str]:
153
greet = solution() env = setup_environment('greet',greet) template = env.from_string(''' {{ 'World'| greet }}''') assertion_results = 'Hi, World!' in template.render(prefix='Hi') assert assertion_results assertion_results = 'Hello, World!' in template.render() assert assertion_results
@jinja2.contextfilter def greet(ctx, name): prefix = ctx.get('prefix', 'Hello') return f'{prefix}, {name}!' return greet
name change
jinja2.contextfilter
markupsafe==2.0.1
[ "https://jinja.palletsprojects.com/en/stable/api/", "https://jinja.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "greet", "ctx.get" ]
2020-01
null
3.10
jinja2
3.1
Implement the solution function to return a custom filter. This filter should: accept the context and a parameter name, retrieve a variable prefix from the context (defaulting to 'Hello' if not provided), return a greeting message combining the prefix and the name.. Do not run the app in your code.
import jinja2 from jinja2.runtime import Context from typing import Callable def setup_environment(filtername: str,filter) -> jinja2.Environment: env = jinja2.Environment() env.filters[filtername] = filter return env def solution() -> Callable[[Context, str], str]:
154
greet = solution() env = setup_environment('greet',greet) template = env.from_string(''' {{ 'World'| greet }}''') assertion_results = 'Hi, World!' in template.render(prefix='Hi') assert assertion_results assertion_results = 'Hello, World!' in template.render() assert assertion_results
@jinja2.pass_context def greet(ctx, name): prefix = ctx.get('prefix', 'Hello') return f'{prefix}, {name}!' return greet
name change
jinja2.pass_context
[ "https://jinja.palletsprojects.com/en/stable/api/", "https://jinja.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "greet", "ctx.get" ]
2022-03
null
3.10
jinja2
2.11
Implement the nl2br function which is a custom filter that takes the evaluation context and a text value, then replaces every occurrence of the substring 'Hello' with the HTML string '<br>Hello</br>', while respecting the autoescape setting. You can use the nl2br_core function. Do not run the app in your code.
import re from jinja2 import Environment, evalcontextfilter from markupsafe import Markup, escape from jinja2.runtime import Context from typing import Callable def get_output(env, filter_fn): env.filters['nl2br'] = filter_fn template = env.from_string('{{ text | nl2br }}') output = template.render(text='H...
155
nl2br = solution() env = Environment(autoescape=True) output = get_output(env,nl2br) expected = '<br>Hello</br> World' assert output == expected
@evalcontextfilter def nl2br(eval_ctx, value): return nl2br_core(eval_ctx, value) return nl2br
name change
jinja2.evalcontextfilter
markupsafe==2.0.1
[ "https://jinja.palletsprojects.com/en/stable/api/", "https://jinja.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "nl2br", "nl2br_core" ]
2020-01
null
3.10
jinja2
3.1
Write the nl2br function which is a custom filter that takes the evaluation context and a text value, then replaces every occurrence of the substring 'Hello' with the HTML string '<br>Hello</br>', while respecting the autoescape setting. You can use the nl2br_core function. Do not run the app in your code.
import re from jinja2 import Environment, pass_eval_context from markupsafe import Markup, escape from typing import Callable, Union from jinja2.runtime import EvalContext def get_output(env, filter_fn): env.filters['nl2br'] = filter_fn template = env.from_string('{{ text | nl2br }}') output = template.ren...
156
nl2br_filter = solution() env = Environment(autoescape=True) output = get_output(env,nl2br_filter) expected = '<br>Hello</br> World' assert output == expected
@pass_eval_context def nl2br(eval_ctx, value): return nl2br_core(eval_ctx, value) return nl2br
name change
jinja2.pass_eval_context
[ "https://jinja.palletsprojects.com/en/stable/api/", "https://jinja.palletsprojects.com/en/stable/changes/" ]
1
1
true
[ "nl2br", "nl2br_core" ]
2022-03
null
3.10
scipy
1.11.1
complete the following function that check if all the batch of matrices are invertible, using numpy 1.25.1.
import warnings from scipy.linalg import det import numpy as np warnings.filterwarnings('error') def check_invertibility(matrices: np.ndarray) -> np.bool_:
157
matrices = np.array([ [[1, 2], [3, 4]], [[0, 1], [1, 0]], [[2, 0], [0, 2]] ]) assertion_value = check_invertibility(matrices) assert assertion_value matrices = np.array([ [[1, 2], [3, 4]], [[0, 1], [1, 0]], [[2, 0], [0, 2]], [[0, 0], [...
return np.all(det(matrices))
argument or attribute change
linalg.det
numpy==1.25.1
[ "https://docs.scipy.org/doc/scipy/release/1.11.1-notes.html" ]
1
0
true
[ "numpy.all", "scipy.linalg.det" ]
2023-06
null
3.10
scipy
1.9.1
complete the following function that check if all the batch of matrices are invertible, using numpy 1.21.6
import warnings from scipy.linalg import det import numpy as np warnings.filterwarnings('error') def check_invertibility(matrices : np.ndarray) -> np.bool_ :
158
matrices = np.array([ [[1, 2], [3, 4]], [[0, 1], [1, 0]], [[2, 0], [0, 2]] ]) assertion_value = check_invertibility(matrices) assert assertion_value matrices = np.array([ [[1, 2], [3, 4]], [[0, 1], [1, 0]], [[2, 0], [0, 2]], [[0, 0], [...
return np.alltrue([det(A) for A in matrices])
argument or attribute change
linalg.det
numpy==1.21.6
[ "https://docs.scipy.org/doc/scipy/release/1.9.1-notes.html" ]
1
0
true
[ "numpy.alltrue", "scipy.linalg.det" ]
2022-10
null
3.10
scipy
1.11.1
Complete the function count_unique_hmean that takes a 2D numpy array as input and returns the number of unique harmonic mean values across the rows of the array, counting each nan value as unique. We are using numpy 1.25.1
import numpy as np from scipy.stats import hmean def count_unique_hmean(data: np.ndarray) -> int: # data shape: (n, m) # n: number of arrays # m: number of elements in each array
159
data = np.array([ [1, 2, 3], [2, 2, 2], [1, np.nan, 3], [4, 5, 6], [np.nan, 1, np.nan], [1, 2, 3] ]) assertion_value = count_unique_hmean(data) == 5 assert assertion_value
hmean_values = hmean(np.asarray(data), axis=1) unique_vals = np.unique(hmean_values, equal_nan=False).shape[0] return unique_vals
output change
stats.hmean
numpy==1.25.1
[ "https://docs.scipy.org/doc/scipy/release/1.11.1-notes.html" ]
1
0
true
[ "scipy.stats.hmean", "numpy.unique", "numpy.asarray" ]
2023-06
null
3.10
scipy
1.8.1
Complete the function count_unique_hmean that takes a 2D numpy array as input and returns the number of unique harmonic mean values across the rows of the array, counting each nan value as unique. We are using numpy 1.21.6
import numpy as np from scipy.stats import hmean def count_unique_hmean(data: np.ndarray) -> int: # data shape: (n, m) # n: number of arrays # m: number of elements in each array
160
data = np.array([ [1, 2, 3], [2, 2, 2], [1, np.nan, 3], [4, 5, 6], [np.nan, 1, np.nan], [1, 2, 3] ]) assertion_value = count_unique_hmean(data) == 5 assert assertion_value
hmean_values = [] for arr in data: if np.isnan(arr).any(): hm = np.nan else: hm = hmean(arr) hmean_values.append(hm) hmean_values = np.asarray(hmean_values) non_nan_vals = hmean_values[~np.isnan(hmean_values)] counts_non_nan = np.unique(non_nan_v...
output change
stats.hmean
numpy==1.21.6
[ "https://docs.scipy.org/doc/scipy/release/1.8.1-notes.html" ]
1
0
true
[ "scipy.stats.hmean", "hmean_values.append", "numpy.isnan", "numpy.unique", "numpy.sum", "numpy.asarray", "any" ]
2022-05
null
3.10
scipy
1.11.1
Complete the function compute_hilbert_transform. We are using numpy 1.25.1
import numpy as np from scipy.signal import hilbert def compute_hilbert_transform(a, b, dtype=np.float64): # compute_hilbert_transform should return the Hilbert transform of the # a and b arrays stacked vertically, with safe casting and the specified # dtype. # raise TypeError if needed
161
a = np.array([1.0, 2.0, 3.0], dtype=np.float32) b = np.array([4.0, 5.0, 6.0], dtype=np.float64) assertion_value = False try : compute_hilbert_transform(a, b, dtype=np.float32) except TypeError: assertion_value = True assert assertion_value b=b.astype(np.float32) computed = compute_hilbert_transform(a, b, dtyp...
stacked = np.vstack((a, b), dtype=dtype, casting='safe') return hilbert(stacked)
argument or attribute change
signal.hilbert
numpy==1.25.1
[ "https://docs.scipy.org/doc/scipy/release/1.11.1-notes.html" ]
1
0
true
[ "scipy.signal.hilbert", "numpy.vstack" ]
2023-06
null
3.10
scipy
1.8.1
Complete the function compute_hilbert_transform. We are using numpy 1.25.1
import numpy as np from scipy.signal import hilbert def compute_hilbert_transform(a: np.ndarray, b: np.ndarray, dtype=np.float64) -> np.ndarray: # compute_hilbert_transform should return the Hilbert transform of the # a and b arrays stacked vertically, with safe casting and the specified # dtype. # rai...
162
a = np.array([1.0, 2.0, 3.0], dtype=np.float32) b = np.array([4.0, 5.0, 6.0], dtype=np.float64) assertion_value = False try : compute_hilbert_transform(a, b, dtype=np.float32) except TypeError: assertion_value = True assert assertion_value b=b.astype(np.float32) computed = compute_hilbert_transform(a, b, dtype...
if not (np.can_cast(a.dtype, dtype, casting='safe') and np.can_cast(b.dtype, dtype, casting='safe')): raise TypeError('Unsafe casting from input dtype to specified dtype') a_cast = a.astype(dtype, copy=False) b_cast = b.astype(dtype, copy=False) stacked = np.vstack((a_cast, b_cast)) ...
argument or attribute change
signal.hilbert
numpy==1.21.6
[ "https://docs.scipy.org/doc/scipy/release/1.8.1-notes.html" ]
1
0
true
[ "b.astype", "TypeError", "scipy.signal.hilbert", "numpy.vstack", "a.astype", "not", "numpy.can_cast", "result.astype" ]
2022-05
null
3.10
flask
2.0.0
Complete the app set-up for the json encoding to return only the unique values (each NaN being a different value) contained in the numpy array when called, we are using numpy 1.21.6. Do not run the app in your code.
import flask import json import numpy as np app = flask.Flask('test1') @app.route('/data') def data(num_arr): return flask.jsonify({'numbers': num_arr}) def eval(app, data_fn, num_arr): with app.test_request_context(): response = data_fn(num_arr) return response.get_data(as_text=False) class M...
163
app2 = flask.Flask('test2') @app2.route('/data2') def data2(num_arr): return flask.jsonify({'numbers': num_arr}) class MyCustomJSONHandler2(json.JSONEncoder): def default(self, obj): if isinstance(obj, np.ndarray): n_nan = np.sum(np.isnan(obj)) unique_vals = obj[~np.isnan(obj)] ...
n_nan = np.sum(np.isnan(obj)) unique_vals = obj[~np.isnan(obj)] unique_vals = np.append(np.unique(unique_vals), [np.nan]*n_nan).tolist() return unique_vals return super().default(obj) app.json_encoder = MyCustomJSONHandler
argument or attribute change
app.json_encoder
numpy==1.21.6 werkzeug==2.0.0
[ "https://flask.palletsprojects.com/en/stable/api/", "https://numpy.org/devdocs/release/1.21.0-notes.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
0
1
true
[ "numpy.append", "default", "numpy.unique", "numpy.isnan", "numpy.sum", "tolist", "super" ]
2021-05
null
3.10
flask
3.0.0
Complete the app set-up for the json encoding to return only the unique values (each NaN being a different value) contained in the numpy array when called, we are using numpy 1.25.1. Do not run the app in your code.
import flask import numpy as np app = flask.Flask('test1') @app.route('/data') def data(num_arr): return flask.jsonify({'numbers': num_arr}) def eval_app(app, data_fn, num_arr): with app.test_request_context(): response = data_fn(num_arr) return response.get_data(as_text=True) class MyCustom...
164
app2 = flask.Flask('test2') @app2.route('/data2') def data2(num_arr): return flask.jsonify({'numbers': num_arr}) class MyCustomJSONHandler2(flask.json.provider.DefaultJSONProvider): def default(self, obj): if isinstance(obj, np.ndarray): n_nan = np.sum(np.isnan(obj)) unique_va...
if isinstance(obj, np.ndarray): unique_vals = np.unique(obj, equal_nan=False) return unique_vals.tolist() return super().default(obj) app.json_provider_class = MyCustomJSONHandler app.json = app.json_provider_class(app)
argument or attribute change
app.json_encoder
numpy==1.25.1
[ "https://flask.palletsprojects.com/en/stable/api/", "https://numpy.org/doc/2.2/release/1.25.0-notes.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
0
1
true
[ "default", "isinstance", "numpy.unique", "unique_vals.tolist", "super", "app.json_provider_class" ]
2023-09
null
3.10
flask
2.0.0
Complete the app set-up for the json encoding to perform a fast copy and transpose when given a numpy array before flattening and converting the result to a list,we are using numpy 1.21.6. Do not run the app in your code.
import flask import json import numpy as np from numpy import fastCopyAndTranspose app = flask.Flask('test1') @app.route('/data') def data(num_arr): return flask.jsonify({'numbers': num_arr}) def eval(app, data_fn, num_arr): with app.test_request_context(): response = data_fn(num_arr) return r...
165
app2 = flask.Flask('test2') @app2.route('/data2') def data2(num_arr): return flask.jsonify({'numbers': num_arr}) class MyCustomJSONHandler2(json.JSONEncoder): def default(self, obj): if isinstance(obj, np.ndarray): res = obj.T.copy().flatten().tolist() return res return ...
res = fastCopyAndTranspose(obj).flatten().tolist() return res return super().default(obj) app.json_encoder = MyCustomJSONHandler
argument or attribute change
app.json_encoder
numpy==1.21.6 werkzeug==2.0.0
[ "https://flask.palletsprojects.com/en/stable/api/", "https://numpy.org/devdocs/release/1.24.0-notes.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
0
1
true
[ "default", "numpy.fastCopyAndTranspose", "flatten", "tolist", "super" ]
2021-05
null
3.10
flask
3.0.0
Complete the app set-up for the json encoding to perform a fast copy and transpose when given a numpy array before flattening and converting the result to a list, we are using numpy 1.25.1. Do not run the app in your code.
import flask import numpy as np import warnings from numpy import fastCopyAndTranspose warnings.filterwarnings('error') app = flask.Flask('test1') @app.route('/data') def data(num_list): return flask.jsonify({'numbers': num_list}) def eval_app(app, data_fn, num_arr): with app.test_request_context(): ...
166
app2 = flask.Flask('test2') @app2.route('/data2') def data2(num_arr): return flask.jsonify({'numbers': num_arr}) class MyCustomJSONHandler2(flask.json.provider.DefaultJSONProvider): def default(self, obj): if isinstance(obj, np.ndarray): res = obj.T.copy().flatten().tolist() r...
res = obj.T.copy().flatten().tolist() return res return super().default(obj) app.json_provider_class = MyCustomJSONHandler app.json = app.json_provider_class(app)
argument or attribute change
app.json_encoder
numpy==1.25.1
[ "https://flask.palletsprojects.com/en/stable/api/", "https://numpy.org/doc/2.2/release/1.25.0-notes.html", "https://flask.palletsprojects.com/en/stable/changes/" ]
0
1
true
[ "default", "obj.T.copy", "flatten", "tolist", "super", "app.json_provider_class" ]
2023-09
null
3.10
flask
2.0.0
Complete the stack_and_save function, we are using numpy 1.21.6. Do not run the app in your code.
import flask import werkzeug import numpy as np error404 = werkzeug.exceptions.NotFound def stack_and_save(arr_list: list[np.ndarray],base_path : str,sub_path : str, casting_policy: str, out_dtype: type) -> tuple[str, np.ndarray]: # Attempt to join the base path and sub path. # If the joined path is outside t...
167
base_path = '/var/www/myapp' sub_path = '../secret.txt' a = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) b = np.array([[7, 8, 9], [10, 11, 12]]).astype(np.float64) arr_list = [a, b] casting_policy = 'safe' out_dtype=np.float64 stacked_correct = np.vstack(arr_list).astype(np.float64) try : joined, stacked ...
joined = flask.safe_join(base_path, sub_path) casted_list = [] for arr in arr_list: if not np.can_cast(arr.dtype, out_dtype, casting=casting_policy): raise TypeError('Cannot cast array') casted_list.append(arr.astype(out_dtype, copy=False)) stacked = np.vstack(casted_l...
name change
flask.safe_join
numpy==1.21.6 werkzeug==2.0.0
[ "https://tedboy.github.io/flask/werk_doc.tutorial.html", "https://flask.palletsprojects.com/en/stable/changes/", "https://numpy.org/devdocs/release/1.21.0-notes.html" ]
1
1
true
[ "flask.safe_join", "TypeError", "arr.astype", "numpy.vstack", "casted_list.append", "numpy.can_cast" ]
2021-05
null
3.10
flask
3.0.0
Complete the stack_and_save function, we are using numpy 1.25.1. Do not run the app in your code.
import flask import werkzeug import numpy as np error404 = werkzeug.exceptions.NotFound def stack_and_save(arr_list: list[np.ndarray],base_path : str,sub_path : str, casting_policy: str, out_dtype: type) -> tuple[str, np.ndarray]: # Attempt to join the base path and sub path. # If the joined path is outside t...
168
base_path = '/var/www/myapp' sub_path = '../secret.txt' a = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) b = np.array([[7, 8, 9], [10, 11, 12]]).astype(np.float64) arr_list = [a, b] casting_policy = 'safe' out_dtype=np.float64 stacked_correct = np.vstack(arr_list).astype(np.float64) try : joined, stacked...
joined = werkzeug.utils.safe_join(base_path, sub_path) if joined is None: raise error404 stacked = np.vstack(arr_list,casting=casting_policy,dtype=out_dtype) return joined, stacked
name change
flask.safe_join
numpy==1.25.1
[ "https://tedboy.github.io/flask/werk_doc.tutorial.html", "https://flask.palletsprojects.com/en/stable/changes/", "https://numpy.org/doc/2.2/release/1.25.0-notes.html" ]
1
1
true
[ "numpy.vstack", "werkzeug.utils.safe_join" ]
2023-09
null
3.10
flask
3.0.0
Complete the app set-up so that, when given a batch of matrix, the json encoding compute the determinants of each matrix, before flattening and converting the result to a list, we are using scipy 1.11.1. Do not run the app in your code.
import flask import numpy as np from scipy import linalg app = flask.Flask('test1') @app.route('/data') def data(num_list): return flask.jsonify({'numbers': num_list}) def eval_app(app, data_fn, num_arr): with app.test_request_context(): response = data_fn(num_arr) return response.get_data(as_t...
169
app2 = flask.Flask('test2') @app2.route('/data2') def data2(num_arr): return flask.jsonify({'numbers': num_arr}) class MyCustomJSONHandler2(flask.json.provider.DefaultJSONProvider): def default(self, obj): if isinstance(obj, np.ndarray) and len(obj.shape)==3 and obj.shape[-1]==obj.shape[-2] : ...
res = linalg.det(obj) return res.tolist() return super().default(obj) app.json_provider_class = MyCustomJSONHandler app.json = app.json_provider_class(app)
argument or attribute change
app.json_encoder
scipy==1.11.1
[ "https://flask.palletsprojects.com/en/stable/api/", "https://flask.palletsprojects.com/en/stable/changes/", "https://docs.scipy.org/doc/scipy/release/1.11.1-notes.html" ]
0
1
true
[ "default", "scipy.linalg.det", "res.tolist", "super", "app.json_provider_class" ]
2023-09
null
3.10
flask
2.0.0
Complete the app set-up so that, when given a batch of matrix, the json encoding compute the determinants of each matrix, before flattening and converting the result to a list, we are using scipy 1.8.1. Do not run the app in your code.
import flask import json import numpy as np from scipy import linalg app = flask.Flask('test1') @app.route('/data') def data(num_arr): return flask.jsonify({'numbers': num_arr}) def eval(app, data_fn, num_arr): with app.test_request_context(): response = data_fn(num_arr) return response.get_da...
170
app2 = flask.Flask('test2') @app2.route('/data2') def data2(num_arr): return flask.jsonify({'numbers': num_arr}) class MyCustomJSONHandler2(json.JSONEncoder): def default(self, obj): if isinstance(obj, np.ndarray) and len(obj.shape)==3 and obj.shape[-1]==obj.shape[-2] : res = np.zeros(obj.s...
res = np.zeros(obj.shape[0]) for i in range(obj.shape[0]): res[i] = linalg.det(obj[i]) return res.tolist() return super().default(obj) app.json_encoder = MyCustomJSONHandler
argument or attribute change
app.json_encoder
scipy==1.8.1 Werkzeug==2.0.0
[ "https://flask.palletsprojects.com/en/stable/api/", "https://flask.palletsprojects.com/en/stable/changes/", "https://docs.scipy.org/doc/scipy/release/1.8.1-notes.html" ]
0
1
true
[ "default", "scipy.linalg.det", "numpy.zeros", "range", "res.tolist", "super" ]
2021-05
null
3.10
flask
3.0.0
Complete the app set-up so that, when given a batch (first dim) of values, compute the harmonic mean along the second dimension (It should handle nan values), before flattening and converting the result to a list, we are using scipy 1.11.1. Do not run the app in your code.
import flask import numpy as np from scipy.stats import hmean app = flask.Flask('test1') @app.route('/data') def data(num_list): return flask.jsonify({'numbers': num_list}) def eval_app(app, data_fn, num_arr): with app.test_request_context(): response = data_fn(num_arr) return response.get_da...
171
app2 = flask.Flask('test2') @app2.route('/data2') def data2(num_arr): return flask.jsonify({'numbers': num_arr}) class MyCustomJSONHandler2(flask.json.provider.DefaultJSONProvider): def default(self, obj): if isinstance(obj, np.ndarray): res = hmean(obj,axis=1).tolist() return...
res = hmean(obj,axis=1).tolist() return res return super().default(obj) app.json_provider_class = MyCustomJSONHandler app.json = app.json_provider_class(app)
argument or attribute change
app.json_encoder
scipy==1.11.1
[ "https://flask.palletsprojects.com/en/stable/api/", "https://flask.palletsprojects.com/en/stable/changes/", "https://docs.scipy.org/doc/scipy/release/1.11.1-notes.html" ]
0
1
true
[ "default", "scipy.stats.hmean", "tolist", "super", "app.json_provider_class" ]
2023-09
null
3.10
flask
2.0.0
Complete the app set-up so that, when given a batch (first dim) of values, compute the harmonic mean along the second dimension (It should handle nan values), before flattening and converting the result to a list, we are using scipy 1.8.1. Do not run the app in your code.
import flask import json import numpy as np from scipy.stats import hmean app = flask.Flask('test1') @app.route('/data') def data(num_arr): return flask.jsonify({'numbers': num_arr}) def eval(app, data_fn, num_arr): with app.test_request_context(): response = data_fn(num_arr) return response.g...
172
app2 = flask.Flask('test2') @app2.route('/data2') def data2(num_arr): return flask.jsonify({'numbers': num_arr}) class MyCustomJSONHandler2(json.JSONEncoder): def default(self, obj): if isinstance(obj, np.ndarray): res = np.zeros((obj.shape[0],1)) for i_arr in range(obj.shape[0]...
res = np.zeros((obj.shape[0],1)) for i_arr in range(obj.shape[0]): if np.isnan(obj[i_arr]).any(): res[i_arr] = np.nan else: res[i_arr] = hmean(obj[i_arr]) res = res.flatten().tolist() return res ...
argument or attribute change
app.json_encoder
scipy==1.8.1 Werkzeug==2.0.0
[ "https://flask.palletsprojects.com/en/stable/api/", "https://flask.palletsprojects.com/en/stable/changes/", "https://docs.scipy.org/doc/scipy/release/1.8.1-notes.html" ]
0
1
true
[ "res.flatten", "tolist", "default", "scipy.stats.hmean", "numpy.zeros", "numpy.isnan", "range", "any", "super" ]
2021-05
null
3.10
flask
3.0.0
Complete the save_exponential function, we are using scipy 1.11.1. Do not run the app in your code.
import flask import werkzeug from scipy import linalg import numpy as np error404 = werkzeug.exceptions.NotFound def save_exponential(A: np.ndarray, base_path: str, sub_path: str) -> tuple[str, np.ndarray]: # Attempt to join the base path and sub path. # If the joined path is outside the base path, raise a 40...
173
base_path = '/var/www/myapp' sub_path = '../secret.txt' import numpy as np a = np.random.random((4,3,3)) expected = np.zeros(a.shape) for i in range(expected.shape[0]): expected[i] = linalg.expm(a[i]) try : joined, results = save_exponential(a,base_path, sub_path) except werkzeug.exceptions.NotFound as e: ...
joined = werkzeug.utils.safe_join(base_path, sub_path) if joined is None: raise error404 output = linalg.expm(A) return joined, output
name change
flask.safe_join
scipy==1.11.1
[ "https://tedboy.github.io/flask/werk_doc.tutorial.html", "https://flask.palletsprojects.com/en/stable/changes/", "https://docs.scipy.org/doc/scipy/release/1.11.1-notes.html" ]
1
1
true
[ "scipy.linalg.expm", "werkzeug.utils.safe_join" ]
2023-09
null
3.10
flask
2.0.0
Complete the save_exponential function, we are using scipy 1.8.1. Do not run the app in your code.
import flask import werkzeug from scipy import linalg import numpy as np error404 = werkzeug.exceptions.NotFound def save_exponential(A: np.ndarray, base_path: str, sub_path: str) -> tuple[str, np.ndarray]: # Attempt to join the base path and sub path. # If the joined path is outside the base path, raise a 40...
174
base_path = '/var/www/myapp' sub_path = '../secret.txt' import numpy as np a = np.random.random((4,3,3)) expected = np.zeros(a.shape) for i in range(expected.shape[0]): expected[i] = linalg.expm(a[i]) try : joined, results = save_exponential(a,base_path, sub_path) except werkzeug.exceptions.NotFound as e: ...
joined = flask.safe_join(base_path, sub_path) output = np.zeros(A.shape) for i in range(A.shape[0]): output[i] = linalg.expm(A[i]) return joined, output
name change
flask.safe_join
scipy==1.8.1 Werkzeug==2.0.0
[ "https://tedboy.github.io/flask/werk_doc.tutorial.html", "https://flask.palletsprojects.com/en/stable/changes/", "https://docs.scipy.org/doc/scipy/release/1.8.1-notes.html" ]
1
1
true
[ "range", "numpy.zeros", "scipy.linalg.expm", "flask.safe_join" ]
2021-05
null
3.9
sympy
1.9
Create a function named custom_generateRandomSampleDice that accepts two parameters: a die object and an integer X. The function should generate and return a list containing X random outcomes sampled from the given die
from typing import List from sympy.stats import Die, sample import sympy.stats.rv def custom_generateRandomSampleDice(dice: sympy.stats.rv.RandomSymbol, X: int) -> List[int]: return
175
dice = Die('X', 6) import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning def test_custom_generateRandomSampleDice(): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) # Capture all warnings output = custom_generateRan...
[sample(dice) for i in range(X)]
new func/method/class
stats.sample
scipy==1.8.0
[ "https://docs.sympy.org/latest/modules/stats.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "range", "sample" ]
2021-06
null
3.9
sympy
1.9
Create a custom_computeDFT function that accepts an integer parameter n. This function should compute the Discrete Fourier Transform (DFT) matrix of size n times n and show it explicitly.
import sympy from sympy.matrices.expressions.fourier import DFT def custom_computeDFT(n: int) -> sympy.ImmutableDenseMatrix: return
176
import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning from sympy import Matrix, I, Rational def test_custom_computeDFT(): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) # Capture all warnings output = custom_comput...
DFT(n).as_explicit()
new func/method/class
sympy.physics.matrices.mdft
[ "https://docs.sympy.org/latest/modules/physics/matrices.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.matrices.expressions.fourier.DFT", "as_explicit" ]
2021-06
null
3.9
sympy
1.9
Create a function named custom_laplace_transform that takes two parameters, t and z. This function should compute the Laplace transform of the 2×2 identity matrix (eye(2)) with respect to the variable t and the transform variable z using the laplace_transform function from Sympy. The function should return a single tup...
from typing import Tuple from sympy import laplace_transform, symbols, eye import sympy def custom_laplace_transform(t: sympy.Symbol, z: sympy.Symbol) -> Tuple[sympy.Matrix, sympy.Expr, bool]: return
177
t, z = symbols('t z') from sympy import Matrix output = custom_laplace_transform(t,z) expected = (Matrix([ [1/z, 0], [ 0, 1/z] ]), 0, True) assert output == expected
laplace_transform(eye(2), t, z, legacy_matrix=False)
new func/method/class
laplace_transform
[ "https://docs.sympy.org/latest/modules/integrals/integrals.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "eye", "laplace_transform" ]
2021-06
null
3.9
sympy
1.11
Create a function named custom_trace that takes a single parameter n, which represents a numerical input. The function should instantiate a trace object using the provided number and return the resulting trace object.
import sympy.physics.quantum import sympy def custom_trace(n: int) -> sympy.physics.quantum.trace.Tr: return
178
from sympy.physics.quantum.trace import Tr expect = 2 assert custom_trace(2) == expect
sympy.physics.quantum.trace.Tr(n)
breaking change
trace
[ "https://docs.sympy.org/latest/modules/physics/quantum/state.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.physics.quantum.trace.Tr" ]
2022-03
null
3.9
sympy
1.11
Create a custom_preorder_traversal function that instantiate and return the preorder_traversal object with existing expression.
import sympy def custom_preorder_traversal(expr: sympy.Expr) -> sympy.core.basic.preorder_traversal: return
179
expr = sympy.Add(1, sympy.Mul(2, 3)) expect = [7] assert list(custom_preorder_traversal(expr)) == expect
sympy.preorder_traversal(expr)
breaking change
preorder_traversal
[ "https://docs.sympy.org/latest/tutorials/intro-tutorial/manipulation.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.preorder_traversal" ]
2022-03
null
3.9
sympy
1.11
Create a function called custom_parse_mathematica that takes a Mathematica expression (as a string) and converts it into a Sympy expression using the parse_mathematica function. In addition, modify the resulting expression so that every occurrence of the function symbol F is replaced by a new function that, when evalua...
from sympy.parsing.mathematica import parse_mathematica from sympy import Function, Max, Min import sympy def custom_parse_mathematica(expr : str) -> int: return
180
expr = "F[6,4,4]" import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expect = 24 assert custom_parse_mathematica(expr) == expect assert not any(isinstance(warn.message, S...
parse_mathematica(expr).replace(Function("F"), lambda *x: Max(*x)*Min(*x))
new func/method/class
parse_mathematica
[ "https://docs.sympy.org/latest/modules/parsing.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "Min", "Max", "sympy.parsing.mathematica.parse_mathematica", "Function", "replace" ]
2022-08
null
3.9
sympy
1.12
Create a function called custom_pinJoint that creates a pin joint connecting two bodies—a parent and a child. The joint should be defined such that: a PinJoint in the parent to be positioned at parent.frame.x with respect to the mass center, and in the child at -child.frame.x. Return a PinJoint object that properly co...
from sympy.physics.mechanics import Body, PinJoint import sympy.physics.mechanics def custom_pinJoint(parent: sympy.physics.mechanics.Body, child: sympy.physics.mechanics.Body) -> sympy.physics.mechanics.PinJoint: return
181
parent, child = Body('parent'), Body('child') pin = custom_pinJoint(parent, child) expect1 = parent.frame.x expect2 = -child.frame.x assert pin.parent_point.pos_from(parent.masscenter) == expect1 assert pin.child_point.pos_from(child.masscenter) == expect2
PinJoint('pin', parent, child, parent_point=parent.frame.x,child_point=-child.frame.x)
argument change
sympy.physics.mechanics.PinJoint
[ "https://docs.sympy.org/latest/modules/physics/mechanics/masses.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "PinJoint" ]
2023-05
null
3.9
sympy
1.12
Create a function called custom_pinJoint that creates a pin joint connecting two bodies—a parent and a child. Configure the joint such that the connection point on the parent body is at parent.frame.x (relative to its mass center), and the connection point on the child body is at -child.frame.x. The function should ret...
from sympy.physics.mechanics import Body, PinJoint import sympy.physics.mechanics import sympy as sp def custom_pinJoint_connect(parent: sympy.physics.mechanics.Body, child: sympy.physics.mechanics.Body) -> sympy.physics.mechanics.PinJoint: return
182
parent, child = Body('parent'), Body('child') pin = custom_pinJoint_connect(parent, child) assertion_value = isinstance(pin.coordinates, sp.Matrix) assert assertion_value assertion_value = isinstance(pin.speeds, sp.Matrix) assert assertion_value
PinJoint('pin', parent, child, parent_point=parent.frame.x,child_point=-child.frame.x)
output behaviour
sympy.physics.mechanics
[ "https://docs.sympy.org/latest/modules/physics/mechanics/masses.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "PinJoint" ]
2023-05
null
3.9
sympy
1.13
Create a function named custom_check_carmichael that takes an integer parameter n as input. The function should determine whether n is a Carmichael number. It should return the result, which is a Boolean value indicating if n is a Carmichael number.
from sympy import * def custom_check_carmichael(n: int) -> bool: return
183
import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning n = 561 with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) from sympy import is_carmichael expect = True output = custom_check_carmichael(n) assert output == expect ...
is_carmichael(n)
breaking change
sympy.functions.combinatorial.numbers.carmichael.is_carmichael
[ "https://docs.sympy.org/latest/modules/core.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "is_carmichael" ]
2023-07
null
3.9
sympy
1.13
Create a function named custom_function that takes two parameters: an integer n and an integer k. The function should compute the divisor sigma function. The divisor sigma function returns the sum of the k powers of the divisors of n.
from sympy import * def custom_function(n: int, k : int) -> int: return
184
n = 6 k = 1 output = custom_function(n, k) import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expect = 12 assert output == expect assert not any(isinstance(warn.message, ...
divisor_sigma(n, k)
breaking change
sympy.ntheory.factor_.divisor_sigma
[ "https://docs.sympy.org/latest/modules/core.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "divisor_sigma" ]
2023-07
null
3.9
sympy
1.13
Create a function named custom_function that takes two parameters: K and a. Here, K represents a finite field created using the GF class from Sympy, and a is an element of that finite field. The function should convert the field element a into its corresponding integer representation and then return this integer.
from sympy import GF from sympy.polys.domains.finitefield import FiniteField def custom_function(K: FiniteField, a: FiniteField) -> int: return
185
K = GF(6) a = K(8) output = custom_function(K, a) import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expect = 2 assert output == expect assert not any(isinstance(warn.me...
K.to_int(a)
new func/method/class
ModularInteger.to_int()
[ "https://docs.sympy.org/latest/modules/polys/domainsref.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "K.to_int" ]
2023-07
null
3.9
sympy
1.13
Create a custom_generateInertia function that accepts an input and returns a symbolic representation of a rigid body’s inertia tensor relative to a specified reference frame, constructed using the symbolic variables for its principal moments of inertia. Based on the provided code, give the complete function and import ...
from sympy import symbols from sympy.physics.mechanics import ReferenceFrame import sympy.physics.vector def custom_generateInertia(N: sympy.physics.vector.frame.ReferenceFrame, Ixx: sympy.Symbol, Iyy: sympy.Symbol, Izz: sympy.Symbol) -> sympy.physics.vector.dyadic.Dyadic: from sympy.
186
N = ReferenceFrame('N') Ixx, Iyy, Izz = symbols('Ixx Iyy Izz') import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) from sympy.physics.mechanics import inertia expect = Ixx * ...
physics.mechanics import inertia return inertia(N, Ixx, Iyy, Izz)
new func/method/class
sympy.physics.mechanics
[ "https://docs.sympy.org/latest/modules/physics/mechanics/masses.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "inertia" ]
2023-07
null
3.9
sympy
1.13
Implement a function named custom_function that accepts a single parameter eq, which is expected to be a symbolic equation (an instance of Sympy's Eq class). The function should compute the difference and return the expression.
from sympy import * import sympy def custom_function(eq: sympy.Equality) -> sympy.Expr: return
187
x, y = symbols('x y') eq = Eq(x, y) output = custom_function(eq) import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expect = x - y assert output == expect assert not any...
eq.lhs - eq.rhs
new func/method/class
Eq.rewrite(Add)
[ "https://docs.sympy.org/latest/modules/core.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[]
2023-07
null
3.9
sympy
1.13
Create a custom_generatePolyList function that accepts a polynomial object and returns a list of its coefficients based on its internal representation.
from sympy import symbols, Poly import sympy def custom_generatePolyList(poly: sympy.Poly) -> list[int]: return
188
import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning x = symbols('x') p = Poly(x**2 + 2*x + 3) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expect = [1,2,3] assert custom_generatePolyList(p) == expect assert not any...
poly.rep.to_list()
new func/method/class
DMP.rep attribute
[ "https://docs.sympy.org/latest/modules/core.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "poly.rep.to_list" ]
2023-07
null
3.9
sympy
1.13
Using Sympy’s mechanics module, create a mechanical system involving three rigid bodies—a wall, a cart, and a pendulum. The wall serves as the inertial (fixed) reference, while the cart is connected to the wall by a sliding joint along the wall’s x-axis. The pendulum is attached to the cart via a rotational joint about...
from sympy import symbols from sympy.physics.mechanics import ( Particle, PinJoint, PrismaticJoint, RigidBody) import sympy import sympy.physics.mechanics def custom_motion(wall: sympy.physics.mechanics.RigidBody, slider: sympy.physics.mechanics.PrismaticJoint, pin: sympy.physics.mechanics.PinJoint) -> sympy.Matrix: ...
189
l = symbols("l") wall = RigidBody("wall") cart = RigidBody("cart") pendulum = RigidBody("Pendulum") slider = PrismaticJoint("s", wall, cart, joint_axis=wall.x) pin = PinJoint("j", cart, pendulum, joint_axis=cart.z, child_point=l * pendulum.y) from sympy import symbols, Function, Derivative, Matrix, sin,...
System system = System.from_newtonian(wall) system.add_joints(slider, pin) return system.form_eoms()
new func/method/class
sympy.physics.mechanics.JointsMethod
[ "https://docs.sympy.org/latest/modules/physics/mechanics/masses.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.physics.mechanics.System.from_newtonian", "system.add_joints", "system.form_eoms" ]
2023-07
null
3.9
sympy
1.13
Using the SymPy's mechanics module, define a function named custom_body that takes two strings as inputs—one representing the name of a rigid body and the other representing the name of a particle—and returns a tuple containing a rigid body and a particle created with those names.
from sympy.physics.mechanics import * import sympy.physics.mechanics def custom_body(rigid_body_text: str, particle_text: str) -> tuple[sympy.physics.mechanics.RigidBody, sympy.physics.mechanics.Particle]: return
190
rigid_body_text = "rigid_body" particle_text = "particle" import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) exp1, exp2 = custom_body(rigid_body_text, particle_text) assert e...
RigidBody(rigid_body_text), Particle(particle_text)
new func/method/class
sympy.physics.mechanics.Body
[ "https://docs.sympy.org/latest/modules/physics/mechanics/masses.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "RigidBody", "Particle" ]
2023-07
null
3.9
sympy
1.9
Implement a function named custom_symbol that takes an input parameter index, which represents an indexed expression or symbol. The function should extract all the free symbols present in the given indexed object and return it.
from sympy import Indexed, Symbol import sympy from typing import Set def custom_symbol(index: Indexed) -> set[Symbol]: return
191
a = Indexed("A", 0) output = custom_symbol(a) import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) A = Symbol('A') A0 = Indexed('A', 0) expect = {A, A0} assert o...
index.free_symbols
new func/method/class
expr_free_symbols
[ "https://docs.sympy.org/latest/modules/tensor/indexed.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[]
2021-06
null
3.9
sympy
1.9
Write a custom_create_matrix function that takes two lists (first and second) and returns a matrix composed of these two lists as rows.
from sympy import Matrix import sympy def custom_create_matrix(first: sympy.Matrix, second: sympy.Matrix) -> list[int]: return
192
first = [1,2] second =[3,4] import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expected_shape = (2, 2) expected_content: list[list[int]] = [[1, 2], [3, 4]] output =...
Matrix([first, second])
new func/method/class
sympy.polys.solvers.RawMatrix
[ "https://docs.sympy.org/latest/tutorials/intro-tutorial/matrices.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.Matrix" ]
2021-06
null
3.9
sympy
1.9
Write a custom_function that accepts a Sympy Matrix and returns a flat, read-only copy of its data
from sympy import Matrix import sympy def custom_function(matrix: sympy.Matrix) -> list[int]: return
193
m = Matrix([[1, 2], [3, 4]]) output = custom_function(m) output[0] = 100 assertion_value = m[0, 0] == 1 assert assertion_value assertion_value = output[0] == 100 assert assertion_value
matrix.flat()
new func/method/class
DenseMatrix._flat
[ "https://docs.sympy.org/latest/tutorials/intro-tutorial/matrices.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "matrix.flat" ]
2021-06
null
3.9
sympy
1.9
Write a custom_function that accepts a Sympy SparseMatrix and returns its dictionary-of-keys representation.
from sympy import Matrix import sympy def custom_function(matrix: sympy.Matrix) -> list[int]: return
194
m = Matrix([[1, 2], [3, 4]]) output = custom_function(m) output[(0, 0)] = 100 assertion_value = m[0, 0] == 1 assert assertion_value assertion_value = output[(0, 0)] == 100 assert assertion_value
matrix.todok()
new func/method/class
SparseMatrix._todok
[ "https://docs.sympy.org/latest/modules/matrices/sparse.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "matrix.todok" ]
2021-06
null
3.9
sympy
1.10
Write a custom_bottom_up function that applies a bottom-up traversal to expr with a lambda function on each node.
import sympy def custom_bottom_up(expr: sympy.Expr) -> int: return
195
expr = sympy.Add(1, sympy.Mul(2, 3)) expect = 7 assert custom_bottom_up(expr) == expect
sympy.bottom_up(expr, lambda x: x.doit())
breaking change
sympy.bottom_up
[ "https://docs.sympy.org/latest/modules/core.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.bottom_up", "x.doit" ]
2022-03
null
3.9
sympy
1.10
Write a custom_use function that traverses the expression so that every subexpression is evaluated, and returns final evaluated result.
import sympy def custom_use(expr: sympy.Expr) -> int: return
196
expr = sympy.Add(1, sympy.Mul(2, 3)) expect = 7 assert custom_use(expr) == expect
sympy.use(expr, lambda x: x.doit())
breaking change
sympy.use
[ "https://docs.sympy.org/latest/tutorials/intro-tutorial/manipulation.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.use", "x.doit" ]
2022-03
null
3.9
sympy
1.11
Write a custom_is_perfect_square function that check if the input is a perfect square.
import sympy def custom_is_perfect_square(n: int) -> bool: return
197
import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expect = True output = custom_is_perfect_square(4) assert output == expect assert not any(isinstance(warn.me...
sympy.ntheory.primetest.is_square(n)
new func/method/class
carmichael.is_perfect_square
[ "https://docs.sympy.org/latest/modules/ntheory.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.ntheory.primetest.is_square" ]
2023-07
null
3.9
sympy
1.11
Write a custom_is_prime function that check if the input is prime
import sympy def custom_is_prime(n: int) -> bool: return
198
import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expect = True output = custom_is_prime(13) assert output == expect assert not any(isinstance(warn.message, S...
sympy.isprime(n)
new func/method/class
carmichael.is_prime
[ "https://docs.sympy.org/latest/modules/ntheory.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "sympy.isprime" ]
2023-07
null
3.9
sympy
1.11
Write a custom_divides function that checks whether the integer p divides the integer n evenly (i.e., with no remainder).
import sympy def custom_divides(n: int, p: int) -> bool: return
199
import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) expect = True output = custom_divides(10,2) assert output == expect assert not any(isinstance(warn.message, ...
n % p == 0
new func/method/class
carmichael.divides
[ "https://docs.sympy.org/latest/modules/physics/quantum/operator.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[]
2023-07
null
3.9
sympy
1.12
Write a custom_array_to_matrix function that convert input array into matrix by import correct sympy modules.
from sympy import Matrix, symbols, Array import sympy def custom_array_to_matrix(array: sympy.Array) -> sympy.Matrix: from sympy.tensor.array.expressions.
200
a1, a2, a3, a4 = symbols('a1 a2 a3 a4') array_expr = Array([[a1, a2], [a3, a4]]) import warnings from sympy.utilities.exceptions import SymPyDeprecationWarning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", SymPyDeprecationWarning) from sympy.tensor.array.expressions.from_arr...
from_array_to_matrix import convert_array_to_matrix return convert_array_to_matrix(array)
breaking change
sympy.tensor.array.expressions.conv_*
[ "https://docs.sympy.org/latest/modules/matrices/matrices.html", "https://docs.sympy.org/latest/explanation/active-deprecations.html" ]
1
0
true
[ "convert_array_to_matrix" ]
2023-05
null