"The masking of data differs according to the type of entries:\n",
"The masking of data differs according to the type of entries:\n",
"\n",
"\n",
"* if the entries are *int* or *float*, the masking is done exclusively by giving aa boolean array of the same size of the data as argument `mask`, each entry indicating if the corresponding entry in the data array is missing or not\n",
"* if the data entries are not *complex* (e.g., *int* or *float*), argument `mask` must be exclusively a boolean array with the same shape as the data array, each entry indicating if the corresponding entry in the data array is missing or not;\n",
"* if the entries are *complex*, the masking can be done as previously, or by giving boolean arrays of the same size of the data as arguments `mask_amplitude` and `mask_phase`, each entry indicating respectively if the magnitude and the phase of the corresponding entry is missing or not."
"* if the data entries are *complex*, the masking can be done as previously, or by setting argument `complex_masking` to `true` and by giving two boolean arrays `mask_magnitude` and `mask_phase` with the same size with the same shape as the data array, each entry indicating respectively if the magnitude and the phase of the corresponding entry is missing or not."
A `MadArray` is a numpy array with missing elements. It is generated using three types of parameter:
A `MadArray` is a numpy array with missing elements. It is generated using three types of parameter:
***data** as an array of entries, either *int*, *float* or *complex*;
***data** as an array of entries, either *int*, *float* or *complex*;
* a **mask** indicating the missing entries;
* a **mask** indicating the missing entries;
***options** to define the behaviour of the object.
***options** to define the behaviour of the object.
A basic initialisation requires only a data matrix. Without mask, all elements are considered as non-missing
A basic initialisation requires only a data matrix. Without mask, all elements are considered as non-missing
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
frommadarraysimportMadArray
frommadarraysimportMadArray
# initialisation without mask
# initialisation without mask
data=np.random.rand(4,6)
data=np.random.rand(4,6)
A=MadArray(data)
A=MadArray(data)
print(A)
print(A)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Masking
## Masking
The masking of data differs according to the type of entries:
The masking of data differs according to the type of entries:
* if the entries are *int* or *float*, the masking is done exclusively by giving aa boolean array of the same size of the data as argument `mask`, each entry indicating if the corresponding entry in the data array is missing or not
* if the data entries are not *complex* (e.g., *int* or *float*), argument `mask` must be exclusively a boolean array with the same shape as the data array, each entry indicating if the corresponding entry in the data array is missing or not;
* if the entries are *complex*, the masking can be done as previously, or by giving boolean arrays of the same size of the data as arguments `mask_amplitude` and `mask_phase`, each entry indicating respectively if the magnitude and the phase of the corresponding entry is missing or not.
* if the data entries are *complex*, the masking can be done as previously, or by setting argument `complex_masking` to `true` and by giving two boolean arrays `mask_magnitude` and `mask_phase` with the same size with the same shape as the data array, each entry indicating respectively if the magnitude and the phase of the corresponding entry is missing or not.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# initialization with a mask
# initialization with a mask
mask=np.random.random(data.shape)<0.5
mask=np.random.random(data.shape)<0.5
Am=MadArray(data,mask)
Am=MadArray(data,mask)
print(mask)
print(mask)
print(Am)
print(Am)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
A *MadArray* can also be defined from another *MadArray*, for example to copy the object:
A *MadArray* can also be defined from another *MadArray*, for example to copy the object:
There are two different and incompatible ways to index *MadArray*. By default (`masked_indexing=False`), it is similar to the indexing of *nd-array*: both the data matrix and the mask are indexed, and a *MadArray* with the shape defined by the indices is returned:
There are two different and incompatible ways to index *MadArray*. By default (`masked_indexing=False`), it is similar to the indexing of *nd-array*: both the data matrix and the mask are indexed, and a *MadArray* with the shape defined by the indices is returned:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
print(A[0:3,1:3])
print(A[0:3,1:3])
print(Am[0:3,1:3])
print(Am[0:3,1:3])
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
With the other way (`masked_indexing=True`), a MadArray with the shape unchanged is returned, where non-indexed entries are considered as masked.
With the other way (`masked_indexing=True`), a MadArray with the shape unchanged is returned, where non-indexed entries are considered as masked.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
Am4=MadArray(data,mask,masked_indexing=True)
Am4=MadArray(data,mask,masked_indexing=True)
print(Am4[0:3,1:3])
print(Am4[0:3,1:3])
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
This latter approach is adapted to be handled with *scikit-learn* procedures.
This latter approach is adapted to be handled with *scikit-learn* procedures.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Numerical operations
## Numerical operations
Numpy functions apply on *MadArray*, but **without** taking into account the mask
Numpy functions apply on *MadArray*, but **without** taking into account the mask