Skip to content

Commit

Permalink
unumpy.covariance_matrix: init
Browse files Browse the repository at this point in the history
  • Loading branch information
doronbehar committed Oct 25, 2024
1 parent 9a4c275 commit 604df40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unreleased
Fixes:

- fix `readthedocs` configuration so that the build passes (#254)
- Add `unumpy.covariance_matrix`: A vectorized variant of the pure Python function `covariance_matrix` (#265)

3.2.2 2024-July-08
-----------------------
Expand Down
13 changes: 13 additions & 0 deletions uncertainties/unumpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"umatrix",
# Utilities:
"nominal_values",
"covariance_matrix",
"std_devs",
# Classes:
"matrix",
Expand Down Expand Up @@ -70,6 +71,18 @@
),
)

def covariance_matrix(a):
"""
Return an array of covariances of given array's numbers with uncertainties,
given shape ``(d0,d1,d2,...,dN)``, the output shape is
``(d0,d1,d2,...,dN,d0,d1,d2,...,dN)``.
"""
arr = numpy.array(a)
return numpy.reshape(
uncert_core.covariance_matrix(arr.ravel()),
arr.shape*2,
)


def unumpy_to_numpy_matrix(arr):
"""
Expand Down

0 comments on commit 604df40

Please sign in to comment.