How to use the nptyping.Array function in nptyping

To help you get started, we’ve selected a few nptyping examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ramonhagenaars / nptyping / test_nptyping.py View on Github external
def test_isinstance(self):
        arr = np.array([[1, 2, 3],
                        [4, 5, 6],
                        [7, 8, 9],
                        [8, 7, 6]])

        self.assertTrue(isinstance(arr, Array))
        self.assertTrue(isinstance(arr, Array[int, 4, ...]))
        self.assertTrue(isinstance(arr, Array[int, 4]))
        self.assertTrue(isinstance(arr, Array[int, 4, None]))
        self.assertTrue(isinstance(arr, Array[int]))
        self.assertTrue(isinstance(arr, Array[int, ...]))
        self.assertTrue(isinstance(arr, Array[int, ..., 3]))
        self.assertTrue(isinstance(arr, Array[int, ..., ...]))
        self.assertTrue(not isinstance(arr, Array[int, 5, ...]))
        self.assertTrue(not isinstance(arr, Array[int, ..., 5]))
        self.assertTrue(not isinstance(arr, Array[int, 5, 5]))

        self.assertTrue(isinstance(np.array([1.0, 2.0, 3.0]), Array[float]))
        self.assertTrue(not isinstance(np.array([1.0, 2.0, 3.0]), Array[int]))
        self.assertTrue(isinstance(np.array([1.0, 2.0, 3.0]), Array))
        self.assertTrue(isinstance(np.array([]), Array[int]))

        self.assertTrue(isinstance(np.array(['1', '22', '333']), Array[str]))
github ramonhagenaars / nptyping / test_nptyping.py View on Github external
def test_isinstance(self):
        arr = np.array([[1, 2, 3],
                        [4, 5, 6],
                        [7, 8, 9],
                        [8, 7, 6]])

        self.assertTrue(isinstance(arr, Array))
        self.assertTrue(isinstance(arr, Array[int, 4, ...]))
        self.assertTrue(isinstance(arr, Array[int, 4]))
        self.assertTrue(isinstance(arr, Array[int, 4, None]))
        self.assertTrue(isinstance(arr, Array[int]))
        self.assertTrue(isinstance(arr, Array[int, ...]))
        self.assertTrue(isinstance(arr, Array[int, ..., 3]))
        self.assertTrue(isinstance(arr, Array[int, ..., ...]))
        self.assertTrue(not isinstance(arr, Array[int, 5, ...]))
        self.assertTrue(not isinstance(arr, Array[int, ..., 5]))
        self.assertTrue(not isinstance(arr, Array[int, 5, 5]))

        self.assertTrue(isinstance(np.array([1.0, 2.0, 3.0]), Array[float]))
        self.assertTrue(not isinstance(np.array([1.0, 2.0, 3.0]), Array[int]))
        self.assertTrue(isinstance(np.array([1.0, 2.0, 3.0]), Array))
        self.assertTrue(isinstance(np.array([]), Array[int]))
github ramonhagenaars / nptyping / test_nptyping.py View on Github external
def test_instantiation(self):
        with self.assertRaises(TypeError):
            Array()
github iancze / Starfish / Starfish / spectrum.py View on Github external
_wave : numpy.ndarray
        The full wavelength array
    _flux : numpy.ndarray
        The full flux array
    _sigma : numpy.ndarray, optional
        The full sigma array. If None, will default to all 0s. Default is None
    mask : numpy.ndarray, optional
        The full mask. If None, will default to all Trues. Default is None

    Attributes
    ----------
    name : str
    """

    _wave: Array[float]
    _flux: Array[float]
    _sigma: Optional[Array[float]] = None
    mask: Optional[Array[bool]] = None

    def __post_init__(self):
        if self._sigma is None:
            self._sigma = np.zeros_like(self._flux)
        if self.mask is None:
            self.mask = np.ones_like(self._wave, dtype=bool)

    @property
    def wave(self):
        """
        numpy.ndarray : The masked wavelength array
        """
        return self._wave[self.mask]