• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy._dtype函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy._dtype函数的典型用法代码示例。如果您正苦于以下问题:Python _dtype函数的具体用法?Python _dtype怎么用?Python _dtype使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了_dtype函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: op_t_p_z

def op_t_p_z(opstr,indx,J,dtype,N,m,basis,L,**blocks):
	a=blocks.get("a")
	kblock=blocks.get("kblock")
	pblock=blocks.get("pblock")
	zblock=blocks.get("zblock")
	pauli=blocks.get("pauli")

	char = _dtype(dtype).char
	compiled_op = basis_ops.__dict__[char+"_t_p_z_op"]
	row,ME,error = compiled_op(N,m,basis,opstr,indx,J,L,pblock,zblock,kblock,a)

	if error != 0: raise OpstrError(_basis_op_errors[error])

	col = _np.arange(len(basis),dtype=_index_type)
	col=_np.concatenate((col,col))

	mask = row >= 0
	col = col[ mask ]
	row = row[ mask ]
	ME = ME[ mask ]

	if not pauli:
		Nop = len(opstr.replace("I",""))
		ME /= 2.0**(Nop)

	return ME,row,col
开发者ID:weinbe58,项目名称:qspin,代码行数:26,代码来源:constructors.py


示例2: as_ctypes_type

    def as_ctypes_type(dtype):
        """
        Convert a dtype into a ctypes type.

        Parameters
        ----------
        dtype : dtype
            The dtype to convert

        Returns
        -------
        ctypes
            A ctype scalar, union, array, or struct

        Raises
        ------
        NotImplementedError
            If the conversion is not possible

        Notes
        -----
        This function does not losslessly round-trip in either direction.

        ``np.dtype(as_ctypes_type(dt))`` will:
         - insert padding fields
         - reorder fields to be sorted by offset
         - discard field titles

        ``as_ctypes_type(np.dtype(ctype))`` will:
         - discard the class names of ``Structure``s and ``Union``s
         - convert single-element ``Union``s into single-element ``Structure``s
         - insert padding fields

        """
        return _ctype_from_dtype(_dtype(dtype))
开发者ID:gabriekq,项目名称:Text-pic-Mendonca,代码行数:35,代码来源:ctypeslib.py


示例3: prep_simple

    def prep_simple(simple_type, dtype):
        """Given a ctypes simple type, construct and attach an
        __array_interface__ property to it if it does not yet have one.
        """
        try:
            simple_type.__array_interface__
        except AttributeError:
            pass
        else:
            return

        typestr = _dtype(dtype).str
        _typecodes[typestr] = simple_type

        def __array_interface__(self):
            return {
                "descr": [("", typestr)],
                "__ref": self,
                "strides": None,
                "shape": (),
                "version": 3,
                "typestr": typestr,
                "data": (ct.addressof(self), False),
            }

        simple_type.__array_interface__ = property(__array_interface__)
开发者ID:WeatherGod,项目名称:numpy,代码行数:26,代码来源:ctypeslib.py


示例4: op

def op(opstr,indx,J,dtype,basis,**blocks):
	char = _dtype(dtype).char
	compiled_op = basis_ops.__dict__[char+"_spinop"]
	pauli = blocks.get('pauli')
	# row: resilting basis states; -1: state is thrown out (cf FindZState)
	# ME: array of dtype with matrix elements
	# error: see line 11 above

	row,ME,error = compiled_op(basis,opstr,indx,J)


	if error != 0: raise OpstrError(_basis_op_errors[error])


	col = _np.arange(len(basis),dtype=_index_type)
	mask = row >= 0
	col = col[ mask ]
	row = row[ mask ]
	ME = ME[ mask ]

	
	if not pauli:
		Nop = len(opstr.replace("I",""))
		ME /= 2.0**(Nop)



	return ME,row,col
开发者ID:weinbe58,项目名称:qspin,代码行数:28,代码来源:constructors.py


示例5: op_t_pz

def op_t_pz(opstr,indx,J,dtype,pauli,N,m,basis,L,**blocks):
	a=blocks.get("a")
	kblock=blocks.get("kblock")
	pzblock=blocks.get("pzblock")

	char = _dtype(dtype).char
	compiled_op = basis_ops.__dict__[char+"_t_pz_op"]
	col,ME,error = compiled_op(N,m,basis,opstr,indx,J,L,pzblock,kblock,a)

	if error != 0: raise OpstrError(_basis_op_errors[error])

	row=_np.arange(len(basis),dtype=_index_type)
	row=_np.concatenate((row,row))

	mask = col >= 0
	row = row[ mask ]
	col = col[ mask ]
	ME = ME[ mask ]
#	print col,ME

	if not pauli:
		Nop = len(opstr.replace("I",""))
		ME /= 2.0**(Nop)


	return ME,row,col
开发者ID:zenonofelea,项目名称:exact_diag_py,代码行数:26,代码来源:constructors.py


示例6: contents

    def contents(self):
        """
        Get an ndarray viewing the data pointed to by this pointer.

        This mirrors the `contents` attribute of a normal ctypes pointer
        """
        full_dtype = _dtype((self._dtype_, self._shape_))
        full_ctype = ctypes.c_char * full_dtype.itemsize
        buffer = ctypes.cast(self, ctypes.POINTER(full_ctype)).contents
        return frombuffer(buffer, dtype=full_dtype).squeeze(axis=0)
开发者ID:gabriekq,项目名称:Text-pic-Mendonca,代码行数:10,代码来源:ctypeslib.py


示例7: _get_typecodes

def _get_typecodes():
    """ Return a dictionary mapping __array_interface__ formats to ctypes types """
    ct = ctypes
    simple_types = [
        ct.c_byte, ct.c_short, ct.c_int, ct.c_long, ct.c_longlong,
        ct.c_ubyte, ct.c_ushort, ct.c_uint, ct.c_ulong, ct.c_ulonglong,
        ct.c_float, ct.c_double,
    ]

    return {_dtype(ctype).str: ctype for ctype in simple_types}
开发者ID:danielballan,项目名称:numpy,代码行数:10,代码来源:ctypeslib.py


示例8: _get_scalar_type_map

 def _get_scalar_type_map():
     """
     Return a dictionary mapping native endian scalar dtype to ctypes types
     """
     ct = ctypes
     simple_types = [
         ct.c_byte, ct.c_short, ct.c_int, ct.c_long, ct.c_longlong,
         ct.c_ubyte, ct.c_ushort, ct.c_uint, ct.c_ulong, ct.c_ulonglong,
         ct.c_float, ct.c_double,
         ct.c_bool,
     ]
     return {_dtype(ctype): ctype for ctype in simple_types}
开发者ID:gabriekq,项目名称:Text-pic-Mendonca,代码行数:12,代码来源:ctypeslib.py


示例9: as_ctypes

    def as_ctypes(obj):
        """Create and return a ctypes object from a numpy array.  Actually
        anything that exposes the __array_interface__ is accepted."""
        ai = obj.__array_interface__
        if ai["strides"]:
            raise TypeError("strided arrays not supported")
        if ai["version"] != 3:
            raise TypeError("only __array_interface__ version 3 supported")
        addr, readonly = ai["data"]
        if readonly:
            raise TypeError("readonly arrays unsupported")

        dtype = _dtype((ai["typestr"], ai["shape"]))
        result = as_ctypes_type(dtype).from_address(addr)
        result.__keep = obj
        return result
开发者ID:gabriekq,项目名称:Text-pic-Mendonca,代码行数:16,代码来源:ctypeslib.py


示例10: prep_pointer

    def prep_pointer(pointer_obj, shape):
        """Given a ctypes pointer object, construct and
        attach an __array_interface__ property to it if it does not
        yet have one.
        """
        try: pointer_obj.__array_interface__
        except AttributeError: pass
        else: return

        contents = pointer_obj.contents
        dtype = _dtype(type(contents))

        inter = {'version': 3,
                 'typestr': dtype.str,
                 'data': (ct.addressof(contents), False),
                 'shape': shape}

        pointer_obj.__array_interface__ = inter
开发者ID:Adward-R,项目名称:numpy,代码行数:18,代码来源:ctypeslib.py


示例11: op_m

def op_m(opstr,indx,J,dtype,pauli,basis,**blocks):

	char = _dtype(dtype).char
	compiled_op = basis_ops.__dict__[char+"_m_op"]
	col,ME,error = compiled_op(basis,opstr,indx,J)

	if error != 0: raise OpstrError(_basis_op_errors[error])

	row=_np.arange(len(basis),dtype=_index_type)
	mask = col >= 0
	row = row[ mask ]
	col = col[ mask ]
	ME = ME[ mask ]

	if not pauli:
		Nop = len(opstr.replace("I",""))
		ME /= 2.0**(Nop)



	return ME,row,col
开发者ID:zenonofelea,项目名称:exact_diag_py,代码行数:21,代码来源:constructors.py


示例12: prep_simple

    def prep_simple(simple_type, dtype):
        """Given a ctypes simple type, construct and attach an
        __array_interface__ property to it if it does not yet have one.
        """
        try: simple_type.__array_interface__
        except AttributeError: pass
        else: return

        typestr = _dtype(dtype).str
        _typecodes[typestr] = simple_type

        def __array_interface__(self):
            return {'descr': [('', typestr)],
                    '__ref': self,
                    'strides': None,
                    'shape': (),
                    'version': 3,
                    'typestr': typestr,
                    'data': (ct.addressof(self), False),
                    }

        simple_type.__array_interface__ = property(__array_interface__)
开发者ID:Adward-R,项目名称:numpy,代码行数:22,代码来源:ctypeslib.py


示例13: op_pz

def op_pz(opstr,indx,J,dtype,N,basis,L,**blocks):
	pzblock=blocks.get("pzblock")
	pauli=blocks.get("pauli")

	char = _dtype(dtype).char
	compiled_op = basis_ops.__dict__[char+"_pz_op"]
	row,ME,error = compiled_op(N,basis,opstr,indx,J,L,pzblock)

	if error != 0: raise OpstrError(_basis_op_errors[error])

	col = _np.arange(len(basis),dtype=_index_type)
	mask = row >= 0
	col = col[ mask ]
	row = row[ mask ]
	ME = ME[ mask ]

	if not pauli:
		Nop = len(opstr.replace("I",""))
		ME /= 2.0**(Nop)



	return ME,row,col
开发者ID:weinbe58,项目名称:qspin,代码行数:23,代码来源:constructors.py


示例14: ndpointer

def ndpointer(dtype=None, ndim=None, shape=None, flags=None):
    """
    Array-checking restype/argtypes.

    An ndpointer instance is used to describe an ndarray in restypes
    and argtypes specifications.  This approach is more flexible than
    using, for example, ``POINTER(c_double)``, since several restrictions
    can be specified, which are verified upon calling the ctypes function.
    These include data type, number of dimensions, shape and flags.  If a
    given array does not satisfy the specified restrictions,
    a ``TypeError`` is raised.

    Parameters
    ----------
    dtype : data-type, optional
        Array data-type.
    ndim : int, optional
        Number of array dimensions.
    shape : tuple of ints, optional
        Array shape.
    flags : str or tuple of str
        Array flags; may be one or more of:

          - C_CONTIGUOUS / C / CONTIGUOUS
          - F_CONTIGUOUS / F / FORTRAN
          - OWNDATA / O
          - WRITEABLE / W
          - ALIGNED / A
          - UPDATEIFCOPY / U

    Returns
    -------
    klass : ndpointer type object
        A type object, which is an ``_ndtpr`` instance containing
        dtype, ndim, shape and flags information.

    Raises
    ------
    TypeError
        If a given array does not satisfy the specified restrictions.

    Examples
    --------
    >>> clib.somefunc.argtypes = [np.ctypeslib.ndpointer(dtype=np.float64,
    ...                                                  ndim=1,
    ...                                                  flags='C_CONTIGUOUS')]
    >>> clib.somefunc(np.array([1, 2, 3], dtype=np.float64))

    """

    if dtype is not None:
        dtype = _dtype(dtype)
    num = None
    if flags is not None:
        if isinstance(flags, str):
            flags = flags.split(',')
        elif isinstance(flags, (int, integer)):
            num = flags
            flags = _flags_fromnum(num)
        elif isinstance(flags, flagsobj):
            num = flags.num
            flags = _flags_fromnum(num)
        if num is None:
            try:
                flags = [x.strip().upper() for x in flags]
            except:
                raise TypeError, "invalid flags specification"
            num = _num_fromflags(flags)
    try:
        return _pointer_type_cache[(dtype, ndim, shape, num)]
    except KeyError:
        pass
    if dtype is None:
        name = 'any'
    elif dtype.names:
        name = str(id(dtype))
    else:
        name = dtype.str
    if ndim is not None:
        name += "_%dd" % ndim
    if shape is not None:
        try:
            strshape = [str(x) for x in shape]
        except TypeError:
            strshape = [str(shape)]
            shape = (shape,)
        shape = tuple(shape)
        name += "_"+"x".join(strshape)
    if flags is not None:
        name += "_"+"_".join(flags)
    else:
        flags = []
    klass = type("ndpointer_%s"%name, (_ndptr,),
                 {"_dtype_": dtype,
                  "_shape_" : shape,
                  "_ndim_" : ndim,
                  "_flags_" : num})
    _pointer_type_cache[dtype] = klass
    return klass
开发者ID:DDRBoxman,项目名称:Spherebot-Host-GUI,代码行数:99,代码来源:ctypeslib.py


示例15: ndpointer

def ndpointer(dtype=None, ndim=None, shape=None, flags=None):
    """Array-checking restype/argtypes.

    An ndpointer instance is used to describe an ndarray in restypes
    and argtypes specifications.  This approach is more flexible than
    using, for example,

    POINTER(c_double)

    since several restrictions can be specified, which are verified
    upon calling the ctypes function.  These include data type
    (dtype), number of dimensions (ndim), shape and flags (e.g.
    'C_CONTIGUOUS' or 'F_CONTIGUOUS').  If a given array does not satisfy the
    specified restrictions, a TypeError is raised.

    Example:

        clib.somefunc.argtypes = [ndpointer(dtype=float64,
                                            ndim=1,
                                            flags='C_CONTIGUOUS')]
        clib.somefunc(array([1,2,3],dtype=float64))

    """

    if dtype is not None:
        dtype = _dtype(dtype)
    num = None
    if flags is not None:
        if isinstance(flags, str):
            flags = flags.split(',')
        elif isinstance(flags, (int, integer)):
            num = flags
            flags = _flags_fromnum(num)
        elif isinstance(flags, flagsobj):
            num = flags.num
            flags = _flags_fromnum(num)
        if num is None:
            try:
                flags = [x.strip().upper() for x in flags]
            except:
                raise TypeError, "invalid flags specification"
            num = _num_fromflags(flags)
    try:
        return _pointer_type_cache[(dtype, ndim, shape, num)]
    except KeyError:
        pass
    if dtype is None:
        name = 'any'
    elif dtype.names:
        name = str(id(dtype))
    else:
        name = dtype.str
    if ndim is not None:
        name += "_%dd" % ndim
    if shape is not None:
        try:
            strshape = [str(x) for x in shape]
        except TypeError:
            strshape = [str(shape)]
            shape = (shape,)
        shape = tuple(shape)
        name += "_"+"x".join(strshape)
    if flags is not None:
        name += "_"+"_".join(flags)
    else:
        flags = []
    klass = type("ndpointer_%s"%name, (_ndptr,),
                 {"_dtype_": dtype,
                  "_shape_" : shape,
                  "_ndim_" : ndim,
                  "_flags_" : num})
    _pointer_type_cache[dtype] = klass
    return klass
开发者ID:radical-software,项目名称:radicalspam,代码行数:73,代码来源:ctypeslib.py



注:本文中的numpy._dtype函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.a函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.__getattribute__函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap