You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Context
The Chebyshev distance $\mathrm{d}(u, v) \overset{\text{def}}{=} \underset{1\leq i \leq n}{\max}\left|u_i-v_i\right|$ can be computed in scipy.spatial.distance by using chebyshev(u, v).
The last line of this chebyshev function is:
returnmax(abs(u-v))
where u and v are two NDArrays.
Benchmark
A basic benchmark shows that for len(a) > 13, the use of max(a) is less efficient than the use of np.max(a) or the use of a.max().
In this benchmark:
a = np.random.random(n),
each point quantifies the time of 20 computations of the considered max function.
Describe the solution you'd like.
Replace:
returnmax(abs(u-v))
By:
returnabs(u-v).max()
At least if len(u) > something.
Describe alternatives you've considered.
No response
Additional context (e.g. screenshots, GIFs)
Code of the benchmark
The code of the benchmark is short, we include it in this additional context:
importperfplotimportnumpyasnpperfplot.show(
setup=lambdan: np.random.random(n),
kernels=[
lambdaa : [max(a) for_inrange(20)],
lambdaa : [np.max(a) for_inrange(20)],
lambdaa : [a.max() for_inrange(20)],
],
labels=['max', 'np.max', 'ndarray.max'],
n_range=[int(1.2**k) forkinrange(10, 92, 2)],
xlabel='len(a)',
title='Comparison of time for max, np.max, and ndarray.max of a NumPy array'
)
Additional remark
Note that the differences of time for the abs functions/method are negligible (ndarray.abs is here ndarray.__abs__).
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Context
The Chebyshev distance$\mathrm{d}(u, v) \overset{\text{def}}{=} \underset{1\leq i \leq n}{\max}\left|u_i-v_i\right|$ can be computed in
scipy.spatial.distance
by usingchebyshev(u, v)
.The last line of this
chebyshev
function is:where
u
andv
are two NDArrays.Benchmark
A basic benchmark shows that for
len(a) > 13
, the use ofmax(a)
is less efficient than the use ofnp.max(a)
or the use ofa.max()
.In this benchmark:
a = np.random.random(n)
,Describe the solution you'd like.
Replace:
By:
At least if
len(u) > something
.Describe alternatives you've considered.
No response
Additional context (e.g. screenshots, GIFs)
Code of the benchmark
The code of the benchmark is short, we include it in this additional context:
Additional remark
Note that the differences of time for the
abs
functions/method are negligible (ndarray.abs
is herendarray.__abs__
).The text was updated successfully, but these errors were encountered: