-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unumpy.average: init #265
base: master
Are you sure you want to change the base?
unumpy.average: init #265
Conversation
315b57a
to
9133c73
Compare
9133c73
to
3585feb
Compare
uncertainties/unumpy/core.py
Outdated
new_shape = [] | ||
# To hold the product of the dimensions to flatten | ||
flatten_size = 1 | ||
for i in range(len(arr.shape)): | ||
if i in axes: | ||
flatten_size *= arr.shape[i] # Multiply dimensions to flatten | ||
else: | ||
new_shape.append(arr.shape[i]) # Keep the dimension | ||
# This way the shapes to average over are flattend, in the end. | ||
new_shape.append(flatten_size) | ||
return arr.reshape(*new_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I'm not sure this does the correct thing when the original shape is something like (4,4,4,4,4)
and axes
is something like (1,3)
. Suggestions are more then welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I'm not sure this does the correct thing when the original shape is something like
(4,4,4,4,4)
andaxes
is something like(1,3)
. Suggestions are more then welcome.
I fixed that using numpy.apply_along_axis
for every axis recursively.
3585feb
to
82a99cd
Compare
for axis in sorted(axes, reverse=True): | ||
arr = numpy.apply_over_axis(_average, axis, arr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm on a 2nd thought, perhaps this means that e.g for A
with shape=(3,4,5,7)
, and axes=(1,3)
, if there are correlations between A[:,0,:,0]
and A[:,1,:,1]
are not taken into account? Because once axis=1
is averaged, the covariance_matrix
call for the 1d slices of axis 1 won't take into account the correlations to the values already averaged on axis 3...
I think we can live with that, but perhaps warn the users about it in the function's doc, or elsewhere. Unless of course someone here will think of a better way to implement this.
It sounds like you are writing code to extract the standard error on the mean of a sequence of Maybe consider first writing code that does this and then consider extending to taking means along slices of arrays of |
82a99cd
to
3114177
Compare
Hello and thanks for joining the discussion!
Correct.
That's what I did eventually in the last attempt, but I'm pretty sure that correlations between values in different axes are not taken into consideration in that case (see my comment above). I reworded the function's |
ruff check
with no errors related to my changes, and ranruff format
on the changed files.unumpy.average
function.