Returns element-wise base array raised to power from second array. This is the masked array version of `numpy.power`. For details see `numpy.power`. See Also -------- numpy.power Notes ----- The *out* argument to `numpy.power` is not supported, `third` has to
(a, b, third=None)
| 6919 | |
| 6920 | |
| 6921 | def power(a, b, third=None): |
| 6922 | """ |
| 6923 | Returns element-wise base array raised to power from second array. |
| 6924 | |
| 6925 | This is the masked array version of `numpy.power`. For details see |
| 6926 | `numpy.power`. |
| 6927 | |
| 6928 | See Also |
| 6929 | -------- |
| 6930 | numpy.power |
| 6931 | |
| 6932 | Notes |
| 6933 | ----- |
| 6934 | The *out* argument to `numpy.power` is not supported, `third` has to be |
| 6935 | None. |
| 6936 | |
| 6937 | Examples |
| 6938 | -------- |
| 6939 | >>> import numpy.ma as ma |
| 6940 | >>> x = [11.2, -3.973, 0.801, -1.41] |
| 6941 | >>> mask = [0, 0, 0, 1] |
| 6942 | >>> masked_x = ma.masked_array(x, mask) |
| 6943 | >>> masked_x |
| 6944 | masked_array(data=[11.2, -3.973, 0.801, --], |
| 6945 | mask=[False, False, False, True], |
| 6946 | fill_value=1e+20) |
| 6947 | >>> ma.power(masked_x, 2) |
| 6948 | masked_array(data=[125.43999999999998, 15.784728999999999, |
| 6949 | 0.6416010000000001, --], |
| 6950 | mask=[False, False, False, True], |
| 6951 | fill_value=1e+20) |
| 6952 | >>> y = [-0.5, 2, 0, 17] |
| 6953 | >>> masked_y = ma.masked_array(y, mask) |
| 6954 | >>> masked_y |
| 6955 | masked_array(data=[-0.5, 2.0, 0.0, --], |
| 6956 | mask=[False, False, False, True], |
| 6957 | fill_value=1e+20) |
| 6958 | >>> ma.power(masked_x, masked_y) |
| 6959 | masked_array(data=[0.29880715233359845, 15.784728999999999, 1.0, --], |
| 6960 | mask=[False, False, False, True], |
| 6961 | fill_value=1e+20) |
| 6962 | |
| 6963 | """ |
| 6964 | if third is not None: |
| 6965 | raise MaskError("3-argument power not supported.") |
| 6966 | # Get the masks |
| 6967 | ma = getmask(a) |
| 6968 | mb = getmask(b) |
| 6969 | m = mask_or(ma, mb) |
| 6970 | # Get the rawdata |
| 6971 | fa = getdata(a) |
| 6972 | fb = getdata(b) |
| 6973 | # Get the type of the result (so that we preserve subclasses) |
| 6974 | if isinstance(a, MaskedArray): |
| 6975 | basetype = type(a) |
| 6976 | else: |
| 6977 | basetype = MaskedArray |
| 6978 | # Get the result and view it as a (subclass of) MaskedArray |