當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.complex256方法代碼示例

本文整理匯總了Python中numpy.complex256方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.complex256方法的具體用法?Python numpy.complex256怎麽用?Python numpy.complex256使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.complex256方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_np_builtin

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def test_np_builtin(self):
        self.pod_util(np.int64(42))
        self.pod_util(np.int32(42))
        self.pod_util(np.int16(42))
        self.pod_util(np.int8(42))
        self.pod_util(np.uint64(42))
        self.pod_util(np.uint32(42))
        self.pod_util(np.uint16(42))
        self.pod_util(np.uint8(42))
        self.pod_util(np.float16(42))
        self.pod_util(np.float32(42))
        self.pod_util(np.float64(42))
        # self.pod_util(np.float128(42))
        self.pod_util(np.complex64(42))
        self.pod_util(np.complex128(42))
        # self.pod_util(np.complex256(42)) 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:18,代碼來源:test_codec.py

示例2: numpy2bifrost

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def numpy2bifrost(dtype):
    if   dtype == np.int8:       return _bf.BF_DTYPE_I8
    elif dtype == np.int16:      return _bf.BF_DTYPE_I16
    elif dtype == np.int32:      return _bf.BF_DTYPE_I32
    elif dtype == np.uint8:      return _bf.BF_DTYPE_U8
    elif dtype == np.uint16:     return _bf.BF_DTYPE_U16
    elif dtype == np.uint32:     return _bf.BF_DTYPE_U32
    elif dtype == np.float16:    return _bf.BF_DTYPE_F16
    elif dtype == np.float32:    return _bf.BF_DTYPE_F32
    elif dtype == np.float64:    return _bf.BF_DTYPE_F64
    elif dtype == np.float128:   return _bf.BF_DTYPE_F128
    elif dtype == ci8:           return _bf.BF_DTYPE_CI8
    elif dtype == ci16:          return _bf.BF_DTYPE_CI16
    elif dtype == ci32:          return _bf.BF_DTYPE_CI32
    elif dtype == cf16:          return _bf.BF_DTYPE_CF16
    elif dtype == np.complex64:  return _bf.BF_DTYPE_CF32
    elif dtype == np.complex128: return _bf.BF_DTYPE_CF64
    elif dtype == np.complex256: return _bf.BF_DTYPE_CF128
    else: raise ValueError("Unsupported dtype: " + str(dtype)) 
開發者ID:ledatelescope,項目名稱:bifrost,代碼行數:21,代碼來源:dtype.py

示例3: numpy2string

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def numpy2string(dtype):
    if   dtype == np.int8:       return 'i8'
    elif dtype == np.int16:      return 'i16'
    elif dtype == np.int32:      return 'i32'
    elif dtype == np.int64:      return 'i64'
    elif dtype == np.uint8:      return 'u8'
    elif dtype == np.uint16:     return 'u16'
    elif dtype == np.uint32:     return 'u32'
    elif dtype == np.uint64:     return 'u64'
    elif dtype == np.float16:    return 'f16'
    elif dtype == np.float32:    return 'f32'
    elif dtype == np.float64:    return 'f64'
    elif dtype == np.float128:   return 'f128'
    elif dtype == np.complex64:  return 'cf32'
    elif dtype == np.complex128: return 'cf64'
    elif dtype == np.complex256: return 'cf128'
    else: raise TypeError("Unsupported dtype: " + str(dtype)) 
開發者ID:ledatelescope,項目名稱:bifrost,代碼行數:19,代碼來源:dtype.py

示例4: test_numpy_dtype_compatibility

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def test_numpy_dtype_compatibility():
    i_a, i_b, i_c = 0, 1, 2
    i_types = [np.intc, np.intp, np.int0, np.int8, np.int16, np.int32, np.int64]
    for i_type in i_types:
        assert cirq.approx_eq(i_type(i_a), i_type(i_b), atol=1)
        assert not cirq.approx_eq(i_type(i_a), i_type(i_c), atol=1)
    u_types = [np.uint, np.uint0, np.uint8, np.uint16, np.uint32, np.uint64]
    for u_type in u_types:
        assert cirq.approx_eq(u_type(i_a), u_type(i_b), atol=1)
        assert not cirq.approx_eq(u_type(i_a), u_type(i_c), atol=1)

    f_a, f_b, f_c = 0, 1e-8, 1
    f_types = [np.float16, np.float32, np.float64]
    if hasattr(np, 'float128'):
        f_types.append(np.float128)
    for f_type in f_types:
        assert cirq.approx_eq(f_type(f_a), f_type(f_b), atol=1e-8)
        assert not cirq.approx_eq(f_type(f_a), f_type(f_c), atol=1e-8)

    c_a, c_b, c_c = 0, 1e-8j, 1j
    c_types = [np.complex64, np.complex128]
    if hasattr(np, 'complex256'):
        c_types.append(np.complex256)
    for c_type in c_types:
        assert cirq.approx_eq(c_type(c_a), c_type(c_b), atol=1e-8)
        assert not cirq.approx_eq(c_type(c_a), c_type(c_c), atol=1e-8) 
開發者ID:quantumlib,項目名稱:Cirq,代碼行數:28,代碼來源:approximate_equality_protocol_test.py

示例5: test_approx_eq_mixed_types

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def test_approx_eq_mixed_types():
    assert cirq.approx_eq(np.float32(1), 1.0 + 1e-10, atol=1e-9)
    assert cirq.approx_eq(np.float64(1), np.complex64(1 + 1e-8j), atol=1e-4)
    assert cirq.approx_eq(np.uint8(1), np.complex64(1 + 1e-8j), atol=1e-4)
    if hasattr(np, 'complex256'):
        assert cirq.approx_eq(np.complex256(1), complex(1, 1e-8), atol=1e-4)
    assert cirq.approx_eq(np.int32(1), 1, atol=1e-9)
    assert cirq.approx_eq(complex(0.5, 0), Fraction(1, 2), atol=0.0)
    assert cirq.approx_eq(0.5 + 1e-4j, Fraction(1, 2), atol=1e-4)
    assert cirq.approx_eq(0, Fraction(1, 100000000), atol=1e-8)
    assert cirq.approx_eq(np.uint16(1), Decimal('1'), atol=0.0)
    assert cirq.approx_eq(np.float64(1.0), Decimal('1.00000001'), atol=1e-8)
    assert not cirq.approx_eq(np.complex64(1e-5j), Decimal('0.001'), atol=1e-4) 
開發者ID:quantumlib,項目名稱:Cirq,代碼行數:15,代碼來源:approximate_equality_protocol_test.py

示例6: test_equal_up_to_global_mixed_array_types

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def test_equal_up_to_global_mixed_array_types():
    a = [1j, 1, -1j, -1]
    b = [-1, 1j, 1, -1j]
    c = [-1, 1, -1, 1]
    assert cirq.equal_up_to_global_phase(a, tuple(b))
    assert not cirq.equal_up_to_global_phase(a, tuple(c))

    c_types = [np.complex64, np.complex128]
    if hasattr(np, 'complex256'):
        c_types.append(np.complex256)
    for c_type in c_types:
        assert cirq.equal_up_to_global_phase(np.asarray(a, dtype=c_type),
                                             tuple(b))
        assert not cirq.equal_up_to_global_phase(np.asarray(a, dtype=c_type),
                                                 tuple(c))
        assert cirq.equal_up_to_global_phase(np.asarray(a, dtype=c_type), b)
        assert not cirq.equal_up_to_global_phase(np.asarray(a, dtype=c_type), c)

    # Object arrays and mixed array/scalar comparisons.
    assert not cirq.equal_up_to_global_phase([1j], 1j)
    assert not cirq.equal_up_to_global_phase(
        np.asarray([1], dtype=np.complex128), np.exp(1j))
    assert not cirq.equal_up_to_global_phase([1j, 1j], [1j, "1j"])
    assert not cirq.equal_up_to_global_phase([1j], "Non-numeric iterable")
    assert not cirq.equal_up_to_global_phase([], [[]], atol=0.0)


# Dummy container class implementing _equal_up_to_global_phase_
# for homogeneous comparison, with nontrivial getter. 
開發者ID:quantumlib,項目名稱:Cirq,代碼行數:31,代碼來源:equal_up_to_global_phase_protocol_test.py

示例7: default

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def default(self, obj):
        """If input object is an ndarray it will be converted into a dict
        holding dtype, shape and the data, base64 encoded.
        """
        numpy_types = (
            np.bool_,
            # np.bytes_, -- python `bytes` class is not json serializable
            # np.complex64,  -- python `complex` class is not json serializable
            # np.complex128,  -- python `complex` class is not json serializable
            # np.complex256,  -- python `complex` class is not json serializable
            # np.datetime64,  -- python `datetime.datetime` class is not json serializable
            np.float16,
            np.float32,
            np.float64,
            # np.float128,  -- special handling below
            np.int8,
            np.int16,
            np.int32,
            np.int64,
            # np.object_  -- should already be evaluated as python native
            np.str_,
            np.uint8,
            np.uint16,
            np.uint32,
            np.uint64,
            np.void,
        )
        if isinstance(obj, np.ndarray):
            return obj.tolist()
        elif isinstance(obj, numpy_types):
            return obj.item()
        elif isinstance(obj, np.float128):
            return obj.astype(np.float64).item()
        elif isinstance(obj, Decimal):
            return str(obj)
        elif isinstance(obj, datetime):
            return str(obj)
        elif obj is np.ma.masked:
            return str(np.NaN)
        # Let the base class default method raise the TypeError
        return json.JSONEncoder.default(self, obj) 
開發者ID:apache,項目名稱:incubator-sdap-nexus,代碼行數:43,代碼來源:webmodel.py

示例8: test_complex256_dtype_raises_exception

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def test_complex256_dtype_raises_exception(self):
        # complex256 only exists on some platforms
        if hasattr(np, 'complex256'):
            data = np.arange(6, dtype=np.complex256).reshape(3, 2)
            self.assert_dtype_raises_exception(data) 
開發者ID:ccpem,項目名稱:mrcfile,代碼行數:7,代碼來源:test_mrcobject.py

示例9: name_nbit2numpy

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complex256 [as 別名]
def name_nbit2numpy(name, nbit):
    if   name == 'i':
        if   nbit == 8:   return np.int8
        elif nbit == 16:  return np.int16
        elif nbit == 32:  return np.int32
        elif nbit == 64:  return np.int64
        else: raise TypeError("Invalid signed integer type size: %i" % nbit)
    elif name == 'u':
        if   nbit == 8:   return np.uint8
        elif nbit == 16:  return np.uint16
        elif nbit == 32:  return np.uint32
        elif nbit == 64:  return np.uint64
        else: raise TypeError("Invalid unsigned integer type size: %i" % nbit)
    elif name == 'f':
        if   nbit == 16:  return np.float16
        elif nbit == 32:  return np.float32
        elif nbit == 64:  return np.float64
        elif nbit == 128: return np.float128
        else: raise TypeError("Invalid floating-point type size: %i" % nbit)
    elif name == 'ci':
        if   nbit == 8:   return ci8
        elif nbit == 16:  return ci16
        elif nbit == 32:  return ci32
    # elif name in set(['ci', 'cu']):
        # Note: This gives integer types in place of proper complex types
        # return name_nbit2numpy(name[1:], nbit*2)
    elif name == 'cf':
        if   nbit == 16:  return cf16
        elif nbit == 32:  return np.complex64
        elif nbit == 64:  return np.complex128
        elif nbit == 128: return np.complex256
        else: raise TypeError("Invalid complex floating-point type size: %i" %
                              nbit)
    else:
        raise TypeError("Invalid type name: " + name) 
開發者ID:ledatelescope,項目名稱:bifrost,代碼行數:37,代碼來源:dtype.py


注:本文中的numpy.complex256方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。