Returns an array containing the same data with a new shape. Refer to `MaskedArray.reshape` for full documentation. See Also -------- MaskedArray.reshape : equivalent function Examples -------- Reshaping a 1-D array: >>> a = np.ma.array([1, 2, 3, 4]) >>> n
(a, new_shape, order='C')
| 7645 | |
| 7646 | |
| 7647 | def reshape(a, new_shape, order='C'): |
| 7648 | """ |
| 7649 | Returns an array containing the same data with a new shape. |
| 7650 | |
| 7651 | Refer to `MaskedArray.reshape` for full documentation. |
| 7652 | |
| 7653 | See Also |
| 7654 | -------- |
| 7655 | MaskedArray.reshape : equivalent function |
| 7656 | |
| 7657 | Examples |
| 7658 | -------- |
| 7659 | Reshaping a 1-D array: |
| 7660 | |
| 7661 | >>> a = np.ma.array([1, 2, 3, 4]) |
| 7662 | >>> np.ma.reshape(a, (2, 2)) |
| 7663 | masked_array( |
| 7664 | data=[[1, 2], |
| 7665 | [3, 4]], |
| 7666 | mask=False, |
| 7667 | fill_value=999999) |
| 7668 | |
| 7669 | Reshaping a 2-D array: |
| 7670 | |
| 7671 | >>> b = np.ma.array([[1, 2], [3, 4]]) |
| 7672 | >>> np.ma.reshape(b, (1, 4)) |
| 7673 | masked_array(data=[[1, 2, 3, 4]], |
| 7674 | mask=False, |
| 7675 | fill_value=999999) |
| 7676 | |
| 7677 | Reshaping a 1-D array with a mask: |
| 7678 | |
| 7679 | >>> c = np.ma.array([1, 2, 3, 4], mask=[False, True, False, False]) |
| 7680 | >>> np.ma.reshape(c, (2, 2)) |
| 7681 | masked_array( |
| 7682 | data=[[1, --], |
| 7683 | [3, 4]], |
| 7684 | mask=[[False, True], |
| 7685 | [False, False]], |
| 7686 | fill_value=999999) |
| 7687 | |
| 7688 | """ |
| 7689 | # We can't use 'frommethod', it whine about some parameters. Dmmit. |
| 7690 | try: |
| 7691 | return a.reshape(new_shape, order=order) |
| 7692 | except AttributeError: |
| 7693 | _tmp = np.asarray(a).reshape(new_shape, order=order) |
| 7694 | return _tmp.view(MaskedArray) |
| 7695 | |
| 7696 | |
| 7697 | def resize(x, new_shape): |
searching dependent graphs…