Return the dot product of two arrays. This function is the equivalent of `numpy.dot` that takes masked values into account. Note that `strict` and `out` are in different position than in the method version. In order to maintain compatibility with the corresponding method, it is
(a, b, strict=False, out=None)
| 8227 | # extras.py. Note that it is not included in __all__, but rather exported |
| 8228 | # from extras in order to avoid backward compatibility problems. |
| 8229 | def dot(a, b, strict=False, out=None): |
| 8230 | """ |
| 8231 | Return the dot product of two arrays. |
| 8232 | |
| 8233 | This function is the equivalent of `numpy.dot` that takes masked values |
| 8234 | into account. Note that `strict` and `out` are in different position |
| 8235 | than in the method version. In order to maintain compatibility with the |
| 8236 | corresponding method, it is recommended that the optional arguments be |
| 8237 | treated as keyword only. At some point that may be mandatory. |
| 8238 | |
| 8239 | Parameters |
| 8240 | ---------- |
| 8241 | a, b : masked_array_like |
| 8242 | Inputs arrays. |
| 8243 | strict : bool, optional |
| 8244 | Whether masked data are propagated (True) or set to 0 (False) for |
| 8245 | the computation. Default is False. Propagating the mask means that |
| 8246 | if a masked value appears in a row or column, the whole row or |
| 8247 | column is considered masked. |
| 8248 | out : masked_array, optional |
| 8249 | Output argument. This must have the exact kind that would be returned |
| 8250 | if it was not used. In particular, it must have the right type, must be |
| 8251 | C-contiguous, and its dtype must be the dtype that would be returned |
| 8252 | for `dot(a,b)`. This is a performance feature. Therefore, if these |
| 8253 | conditions are not met, an exception is raised, instead of attempting |
| 8254 | to be flexible. |
| 8255 | |
| 8256 | See Also |
| 8257 | -------- |
| 8258 | numpy.dot : Equivalent function for ndarrays. |
| 8259 | |
| 8260 | Examples |
| 8261 | -------- |
| 8262 | >>> import numpy as np |
| 8263 | >>> a = np.ma.array([[1, 2, 3], [4, 5, 6]], mask=[[1, 0, 0], [0, 0, 0]]) |
| 8264 | >>> b = np.ma.array([[1, 2], [3, 4], [5, 6]], mask=[[1, 0], [0, 0], [0, 0]]) |
| 8265 | >>> np.ma.dot(a, b) |
| 8266 | masked_array( |
| 8267 | data=[[21, 26], |
| 8268 | [45, 64]], |
| 8269 | mask=[[False, False], |
| 8270 | [False, False]], |
| 8271 | fill_value=999999) |
| 8272 | >>> np.ma.dot(a, b, strict=True) |
| 8273 | masked_array( |
| 8274 | data=[[--, --], |
| 8275 | [--, 64]], |
| 8276 | mask=[[ True, True], |
| 8277 | [ True, False]], |
| 8278 | fill_value=999999) |
| 8279 | |
| 8280 | """ |
| 8281 | if strict is True: |
| 8282 | if np.ndim(a) == 0 or np.ndim(b) == 0: |
| 8283 | pass |
| 8284 | elif b.ndim == 1: |
| 8285 | a = _mask_propagate(a, a.ndim - 1) |
| 8286 | b = _mask_propagate(b, b.ndim - 1) |