numpy.array.dtype - python examples

Here are the examples of the python api numpy.array.dtype taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

31 Examples 7

3 View Complete Implementation : test_numeric.py
Copyright MIT License
Author : alvarob96
def full_like(array, value):
    """Compatibility for numpy<1.8.0
    """
    ret = np.empty(array.shape, dtype=np.array(value).dtype)
    ret.fill(value)
    return ret

3 View Complete Implementation : utils.py
Copyright Apache License 2.0
Author : google
def astype(array, y):
  """A functional form of the `astype` method.

  Args:
    array: The array or number to cast.
    y: An array or number, as the input, whose type should be that of array.

  Returns:
    An array or number with the same dtype as `y`.
  """
  if isinstance(y, autograd.core.Node):
    return array.astype(numpy.array(y.value).dtype)
  return array.astype(numpy.array(y).dtype)

3 View Complete Implementation : test_block.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : ledatelescope
    def tearDown(self):
        """Run the pipeline and test the output against the expectation"""
        Pipeline(self.blocks).main()
        if np.array(self.expected_result).dtype == 'complex128':
            result = np.loadtxt('.log.txt', dtype=np.float64).view(np.complex128)
        else:
            result = np.loadtxt('.log.txt').astype(np.float32)
        np.testing.astert_almost_equal(result, self.expected_result)

3 View Complete Implementation : test_numpy_array.py
Copyright Apache License 2.0
Author : mlperf
def test_constructors():
    defaults = m.default_constructors()
    for a in defaults.values():
        astert a.size == 0
    astert defaults["array"].dtype == np.array([]).dtype
    astert defaults["array_t<int32>"].dtype == np.int32
    astert defaults["array_t<double>"].dtype == np.float64

    results = m.converting_constructors([1, 2, 3])
    for a in results.values():
        np.testing.astert_array_equal(a, [1, 2, 3])
    astert results["array"].dtype == np.int_
    astert results["array_t<int32>"].dtype == np.int32
    astert results["array_t<double>"].dtype == np.float64

3 View Complete Implementation : catalogue_errors.py
Copyright Mozilla Public License 2.0
Author : nanoporetech
def rle(it):
    """Calculate a run length encoding (rle), of an input vector.

    :param it: iterable.
    :returns: structured array with fields `start`, `length`, and `value`.
    """
    val_dtype = np.array(it[0]).dtype
    dtype = [('length', int), ('start', int), ('value', val_dtype)]

    def _gen():
        start = 0
        for key, group in itertools.groupby(it):
            length = sum(1 for x in group)
            yield length, start, key
            start += length
    return np.fromiter(_gen(), dtype=dtype)

3 View Complete Implementation : value.py
Copyright MIT License
Author : pfnet-research
    def get_attribute(self, key: str, env: 'utils.Env') -> 'Value':
        if not self.is_py:
            raise TypeError('Unsupported attribute %s for an ONNX value' % key)
        value = Value(getattr(self.value, key))
        if (value.is_py and
            (value.value is None or
             not isinstance(value.value, type) and
             # TODO(hamaji): We probably need to create a ValueInfo
             # for Variable.
             not isinstance(value.value, chainer.Variable) and
             np.array(value.value).dtype != np.object)):
            value.to_value_info(env.root())
            setattr(self.value, key, value)
        if not value.is_py:
            env.read_attrs.append((self, key, value))
        return value

3 View Complete Implementation : functions_ndarray.py
Copyright MIT License
Author : pfnet-research
    def vcall(self, module: 'values.Field', graph: 'graphs.Graph', inst: 'values.Object', args: 'functions.FunctionArgInput',
              context: 'functions.VEvalContext' = None, line=-1):
        args = functions.FunctionArgInput()
        args.inputs.append(inst)
        args.keywords['self'] = inst

        node = nodes.NodeCall(self, args, line)

        value = values.NumberValue(None)
        value.dtype = np.array(0).dtype
        value.name = '@F.{}.{}'.format(line, self.name)
        node.set_outputs([value])

        graph.add_node(node)
        return values.Object(value)

3 View Complete Implementation : values.py
Copyright MIT License
Author : pfnet-research
    def __init__(self, number):
        super().__init__()
        self.internal_value = number
        self.dtype = None

        if self.internal_value is not None:
            self.dtype = np.array(self.internal_value).dtype

        if not config.float_restrict and self.dtype == np.float64:
            self.dtype = np.float32

3 View Complete Implementation : values.py
Copyright MIT License
Author : pfnet-research
    def __init__(self, value = None):
        super().__init__()
        self.shape = ()
        self.internal_value = value
        self.value = None   # not used?
        self.dtype = None

        if self.internal_value is not None:
            self.dtype = np.array(self.internal_value).dtype

        if not config.float_restrict and self.dtype == np.float64:
            self.dtype = np.float32

3 View Complete Implementation : test_datasets.py
Copyright MIT License
Author : PhasesResearchLab
def test_datasets_convert_thermochemical_string_values_producing_correct_value(datasets_db):
    """Strings where floats are expected should give correct answers for thermochemical datasets"""
    ds = clean_dataset(CU_MG_DATASET_THERMOCHEMICAL_STRING_VALUES)
    astert np.issubdtype(np.array(ds['values']).dtype, np.number)
    astert np.issubdtype(np.array(ds['conditions']['T']).dtype, np.number)
    astert np.issubdtype(np.array(ds['conditions']['P']).dtype, np.number)