python中dtype的使用规范_Python numpy.dtype() 使用实例

2023-10-29

The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

Example 1

def extract_images(filename):

"""Extract the images into a 4D uint8 numpy array [index, y, x, depth]."""

print('Extracting', filename)

with gzip.open(filename) as bytestream:

magic = _read32(bytestream)

if magic != 2051:

raise ValueError(

'Invalid magic number %d in MNIST image file: %s' %

(magic, filename))

num_images = _read32(bytestream)

rows = _read32(bytestream)

cols = _read32(bytestream)

buf = bytestream.read(rows * cols * num_images)

data = numpy.frombuffer(buf, dtype=numpy.uint8)

data = data.reshape(num_images, rows, cols, 1)

return data

Example 2

def gl_init(self,array_table):

self.gl_hide = False

self.gl_vertex_array = gl.VertexArray()

glBindVertexArray(self.gl_vertex_array)

self.gl_vertex_buffer = gl.Buffer()

glBindBuffer(GL_ARRAY_BUFFER,self.gl_vertex_buffer)

self.gl_element_count = 3*gl_count_triangles(self)

self.gl_element_buffer = gl.Buffer()

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,self.gl_element_buffer)

vertex_type = numpy.dtype([array_table[attribute].field() for attribute in self.attributes])

vertex_count = sum(len(primitive.vertices) for primitive in self.primitives)

vertex_array = numpy.empty(vertex_count,vertex_type)

for attribute in self.attributes:

array_table[attribute].load(self,vertex_array)

vertex_array,element_map = numpy.unique(vertex_array,return_inverse=True)

element_array = gl_create_element_array(self,element_map,self.gl_element_count)

glBufferData(GL_ARRAY_BUFFER,vertex_array.nbytes,vertex_array,GL_STATIC_DRAW)

glBufferData(GL_ELEMENT_ARRAY_BUFFER,element_array.nbytes,element_array,GL_STATIC_DRAW)

Example 3

def extract_images(filename):

"""Extract the images into a 4D uint8 numpy array [index, y, x, depth]."""

print('Extracting', filename)

with gzip.open(filename) as bytestream:

magic = _read32(bytestream)

if magic != 2051:

raise ValueError(

'Invalid magic number %d in MNIST image file: %s' %

(magic, filename))

num_images = _read32(bytestream)

rows = _read32(bytestream)

cols = _read32(bytestream)

buf = bytestream.read(rows * cols * num_images)

data = numpy.frombuffer(buf, dtype=numpy.uint8)

data = data.reshape(num_images, rows, cols, 1)

return data

Example 4

def __keytransform__(self, key):

if isinstance(key[0], np.ndarray):

shape = key[0].shape

dtype = key[0].dtype

i = key[1]

zero = True if len(key) == 2 else key[2]

elif isinstance(key[0], tuple):

if len(key) == 3:

shape, dtype, i = key

zero = True

elif len(key) == 4:

shape, dtype, i, zero = key

else:

raise TypeError("Wrong type of key for work array")

assert isinstance(zero, bool)

assert isinstance(i, int)

self.fillzero = zero

return (shape, np.dtype(dtype), i)

Example 5

def accumulate_strings(values, name="strings"):

"""Accumulates strings into a vector.

Args:

values: A 1-d string tensor that contains values to add to the accumulator.

Returns:

A tuple (value_tensor, update_op).

"""

tf.assert_type(values, tf.string)

strings = tf.Variable(

name=name,

initial_value=[],

dtype=tf.string,

trainable=False,

collections=[],

validate_shape=True)

value_tensor = tf.identity(strings)

update_op = tf.assign(

ref=strings, value=tf.concat([strings, values], 0), validate_shape=False)

return value_tensor, update_op

Example 6

def test_expect_dtypes_with_tuple(self):

allowed_dtypes = (dtype('datetime64[ns]'), dtype('float'))

@expect_dtypes(a=allowed_dtypes)

def foo(a, b):

return a, b

for d in allowed_dtypes:

good_a = arange(3).astype(d)

good_b = object()

ret_a, ret_b = foo(good_a, good_b)

self.assertIs(good_a, ret_a)

self.assertIs(good_b, ret_b)

with self.assertRaises(TypeError) as e:

foo(arange(3, dtype='uint32'), object())

expected_message = (

"{qualname}() expected a value with dtype 'datetime64[ns]' "

"or 'float64' for argument 'a', but got 'uint32' instead."

).format(qualname=qualname(foo))

self.assertEqual(e.exception.args[0], expected_message)

Example 7

def _classify_gems(counts0, counts1):

""" Infer number of distinct transcriptomes present in each GEM (1 or 2) and

report cr_constants.GEM_CLASS_GENOME0 for a single cell w/ transcriptome 0,

report cr_constants.GEM_CLASS_GENOME1 for a single cell w/ transcriptome 1,

report cr_constants.GEM_CLASS_MULTIPLET for multiple transcriptomes """

# Assumes that most of the GEMs are single-cell; model counts independently

thresh0, thresh1 = [cr_constants.DEFAULT_MULTIPLET_THRESHOLD] * 2

if sum(counts0 > counts1) >= 1 and sum(counts1 > counts0) >= 1:

thresh0 = np.percentile(counts0[counts0 > counts1], cr_constants.MULTIPLET_PROB_THRESHOLD)

thresh1 = np.percentile(counts1[counts1 > counts0], cr_constants.MULTIPLET_PROB_THRESHOLD)

doublet = np.logical_and(counts0 >= thresh0, counts1 >= thresh1)

dtype = np.dtype('|S%d' % max(len(cls) for cls in cr_constants.GEM_CLASSES))

result = np.where(doublet, cr_constants.GEM_CLASS_MULTIPLET, cr_constants.GEM_CLASS_GENOME0).astype(dtype)

result[np.logical_and(np.logical_not(result == cr_constants.GEM_CLASS_MULTIPLET), counts1 > counts0)] = cr_constants.GEM_CLASS_GENOME1

return result

Example 8

def widen_cat_column(old_ds, new_type):

name = old_ds.name

tmp_name = "__tmp_" + old_ds.name

grp = old_ds.parent

ds = grp.create_dataset(tmp_name,

data = old_ds[:],

shape = old_ds.shape,

maxshape = (None,),

dtype = new_type,

compression = COMPRESSION,

shuffle = True,

chunks = (CHUNK_SIZE,))

del grp[name]

grp.move(tmp_name, name)

return ds

Example 9

def create_levels(ds, levels):

# Create a dataset in the LEVEL_GROUP

# and store as native numpy / h5py types

level_grp = ds.file.get(LEVEL_GROUP)

if level_grp is None:

# Create a LEVEL_GROUP

level_grp = ds.file.create_group(LEVEL_GROUP)

ds_name = ds.name.split("/")[-1]

dt = h5py.special_dtype(vlen=str)

level_grp.create_dataset(ds_name,

shape = [len(levels)],

maxshape = (None,),

dtype = dt,

data = levels,

compression = COMPRESSION,

chunks = (CHUNK_SIZE,))

Example 10

def reg2bin_vector(begin, end):

'''Vectorized tabix reg2bin -- much faster than reg2bin'''

result = np.zeros(begin.shape)

# Entries filled

done = np.zeros(begin.shape, dtype=np.bool)

for (bits, bins) in rev_bit_bins:

begin_shift = begin >> bits

new_done = (begin >> bits) == (end >> bits)

mask = np.logical_and(new_done, np.logical_not(done))

offset = ((1 << (29 - bits)) - 1) / 7

result[mask] = offset + begin_shift[mask]

done = new_done

return result.astype(np.int32)

Example 11

def flip_code(code):

if isinstance(code, (numpy.dtype,type)):

# since several things map to complex64 we must carefully select

# the opposite that is an exact match (ticket 1518)

if code == numpy.int8:

return gdalconst.GDT_Byte

if code == numpy.complex64:

return gdalconst.GDT_CFloat32

for key, value in codes.items():

if value == code:

return key

return Non

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python中dtype的使用规范_Python numpy.dtype() 使用实例 的相关文章

  • python的launcher用法知识点总结

    更多编程教程请到 菜鸟教程 https www piaodoo com python launcher是适用于 Windows 的 Python 启动器 可帮助您定位和执行不同的 Python 版本 它允许脚本 或命令行 为特定的 Pyth
  • Idea 生成模板代码(Demo)

    1 在html文件中复制需要生成模板的代码 如下图选中部分 ctrl c 2 点击 File gt Settings 如下图 3 选择 Editor gt Live Template 点击右边的 然后点击 1 Live Template 如
  • 【Yarn】Yarn ApplicationMasterLauncher的工作机制

    文章目录 1 概述 2 源码 2 1 类变量 2 2 构造方法 2 4 serviceInit 2 5 serviceStart 2 6 LauncherThread 2 7 launch事件 2 8 AMLauncher的run 1 概述
  • 前端框架Vue(5)——Vue + Echarts (数据可视化)

    Echarts 是数据可视化中佼佼者 推荐大家可以玩一玩 非常实用 如果第一次接触Echarts的同学 这边有我以前写过的一篇入门 浅谈Echarts3 0 Vue Echarts 现附上代码
  • 数据结构作业:实现链表的基本操作

    数据结构作业 实现链表的基本操作 链表是一种常见的数据结构 它由一系列节点组成 每个节点包含数据和指向下一个节点的指针 本文将介绍链表的基本操作 包括创建链表 插入节点 删除节点以及遍历链表 首先 我们需要定义链表节点的结构体 节点包含一个
  • signature=31a231fa44057e3d64bcbe8f86676d0e,typescript-definitions

    THIS IS AN AUTOGENERATED FILE DO NOT EDIT THIS FILE DIRECTLY yarn lockfile v1 continuous auth client 1 1 0 version 1 2 3
  • 2020-04-08

    查看有关计算机的基本信息 1 右键点击 计算机 的 属性 就能看到这台电脑的基本信息了
  • Android Platform 3.0 SDK和Eclipse ADT安装记录(最初版本,纪念用)

    注意 此文非常非常地过时 只是用于个人回想 请参看 二 以后的笔记 20110926 注意 此文由于结构过于混乱且内容过时 将会被删除 用新的学习日记取代 如果我有时间的话 注 我只是为了学习简单的Android编程和模拟 所以没有考虑SD
  • 图示CORDIC算法

    目录 简介 原理 硬件实现 简介 CORDIC Coordinate Rotation Digital Computer 坐标旋转数字计算方法 应用 计算三角函数 cos sin tan 或者计算旋转角 原理 问题 在下图中 C点的坐标是
  • 阿里云教程安装WordPress没有 安装新插件 及 主题 的按钮

    表象 在插件页面和主题页面没有Add New的按钮 经过一番百度后 主要分为两派 文件权限问题 your wordpress site folder如果按照阿里云教程 该地址为 var www html wp blog 解决方案 chown
  • React 项目:计算器

    本教程专注于 React 部分 故对 css 及 js 不做过多解释 项目地址 yuzheng14 calculator github com 分析原型 应用中一共包含 4 个组件 APP 整个应用的整体 Display 展示输入数据及计算
  • 外网SSH远程连接linux服务器「cpolar内网穿透」

    文章目录 1 Linux CentOS安装cpolar 2 创建TCP隧道 3 随机地址公网远程连接 4 固定TCP地址 5 使用固定公网TCP地址SSH远程 本次教程我们来实现如何在外公网环境下 SSH远程连接家里 公司的Linux Ce
  • SpringBoot结合Liquibase实现数据库变更管理

    从零打造项目 系列文章 工具 比MyBatis Generator更强大的代码生成器 ORM框架选型 SpringBoot项目基础设施搭建 SpringBoot集成Mybatis项目实操 SpringBoot集成MybatisPlus项目实
  • Java利用正则表达式获取指定两个字符串之间的内容

    package com starit analyse util import java text SimpleDateFormat import java util ArrayList import java util List impor
  • CentOS 7 下使用 MySQL 5.7 + PHP 7 + Apache 部署 Nextcloud

    准备 如果你准备使用 VPS 或者云主机作为 Nextcloud 服务器的话 可以先安装一个 Xshell 注 以下代码块中 代表注释 代表 Linux 命令 姊妹篇 Ubuntu 16 04 下使用 MySQL 5 7 PHP 7 Apa
  • python对指定字符串逆序的6种方法

    对于一个给定的字符串 逆序输出 这个任务对于python来说是一种很简单的操作 毕竟强大的列表和字符串处理的一些列函数足以应付这些问题 了 今天总结了一下python中对于字符串的逆序输出的几种常用的方法 方法一 直接使用字符串切片功能逆转
  • cuda学习笔记之异步并行执行

    异步函数使得主机端与设备端并行执行 控制在设备还没有完成前就被返回给主机线程 包括 kernel启动 以Async为后缀的内存拷贝函数 device到device内存拷贝函数 存储器初始化函数 比如cudaMemset cudaMemset
  • linux离线安装llvm,Debian/Ubuntu Linux 下安装LLVM/Clang 编译器

    第一步 首先编辑 etc apt sources list 加入以下源 Debian平台 deb http llvm org apt wheezy llvm toolchain wheezy main deb src http llvm o
  • Qt将文件保存到指定目录下(另存为的功能)

    因为Qt才开始入门 对文件的操作还不是很熟练 经过一段时间查找终于找出一些适用于入门的代码 QDir d d mkpath D 123 file new QFile D 123 tmp file gt open QFile WriteOnl

随机推荐

  • MySQL索引实现原理分析

    目前大部分数据库系统及文件系统都采用B Tree B树 或其变种B Tree B 树 作为索引结构 B Tree是数据库系统实现索引的首选数据结构 在 MySQL 中 索引属于存储引擎级别的概念 不同存储引擎对索引的实现方式是不同的 本文主
  • docker安装Apollo,并用java连接测试

    What is Apollo 背景 随着程序功能的日益复杂 程序的配置日益增多 各种功能的开关 参数的配置 服务器的地址 对程序配置的期望值也越来越高 配置修改后实时生效 灰度发布 分环境 分集群管理配置 完善的权限 审核机制 在这样的大环
  • C语言-文件

    C语言 文件 一 为什么使用文件 二 文件的打开与关闭 1 fopen 1 r w a 2 rb wb ab 3 r w a 4 rb wb ab 2 fclose 三 文件顺序读写函数 1 fgetc fputc 2 fgets fput
  • Ubuntu18.04 python 开发usb通信

    一 安装环境 1 安装pip sudo python3 get pip py 或 sudo i apt update apt install python3 pip 确定pip是否安装成功 xxx desktop pip3 version
  • 【Transformers】第 3 章:自动编码语言模型

    大家好 我是Sonhhxg 柒 希望你看完之后 能对你有所帮助 不足请指正 共同学习交流 个人主页 Sonhhxg 柒的博客 CSDN博客 欢迎各位 点赞 收藏 留言 系列专栏 机器学习 ML 自然语言处理 NLP 深度学习 DL fore
  • 瑞吉外卖项目——删除和批量删除套餐功能

    需求分析 用户点击删除按钮 可以删除对应的套餐 也可以通过复选框选择多个套餐 点击批量删除 一次性删除多个套餐 注意 对于状态在售卖中的套餐不能删除 需要先停售 之后才能删除 代码开发 前后端发交互 前端携带id发送请求 请求服务端 服务端
  • 牛客网剑指offer java 全部题解

    经过数月的努力 终于更完了牛客网的66道剑指offer 以下的顺序和大家在牛客网的顺序是一样的 排序也花了不少时间 希望对大家找工作 提高算法能力能起到些许帮助 每天一道剑指offer 二维数组中的查找 https mp weixin qq
  • Redis主从连接失败 connected_slaves:0

    进行主从连接配置时 主服务器使用info replication查到的 connected slaves数一直是0 原因是主服务器设置了密码 找到从服务器的配置文件redis conf 在配置文件中找到 masterauth
  • python如何做敏感度分析,使用SALib工具箱从测量数据进行Python敏感性分析

    I would like to understand how to use the SALib python toolbox to perform a Sobol sensitivity analysis to study paramete
  • IDEA 代码提交前流程及提交日志模板化

    前言 在开发大型项目时 通常都是由团队来进行开发 此时 每个人有每个人的代码编写风格和提交习惯 如果放任自由发挥 那么代码质量和代码提交日志就难免风格各异 导致项目代码质量难以保持统一 针对这一问题 往往公司在以项目组进行开发时 在进入正式
  • [转载]Python正则表达式匹配反斜杠'\'问题

    在学习Python正则式的过程中 有一个问题一直困扰我 如何去匹配一个反斜杠 即 一 引入 在学习了Python特殊字符和原始字符串之后 我觉得答案应该是这样的 1 普通字符串 2 原始字符串 r 但事实上在提取诸如 3 8 反斜杠之前的数
  • 高速PCB电路板的信号完整性设计

    目录 高速PCB电路板的信号完整性设计 1信号完整性基本理论 1 1 信号完整性定义 1 2影响信号完整性的主要因素 2高速数据采集系统 3 信号完整性设计 3 1电路板叠层设计 3 2电路板布局设计 3 3电路板布线设计 一 信号完整性是
  • 编译语言的编译和脚本语言的解释

    编译语言的编译和脚本语言的解释 编译语言和脚本语言 这个博主看了几篇帖子 觉得Jonny工作室的这篇文章解释的最简单明了 联想之间之前写的程序 大胆给一点自己的看法 如有不对还望指正 编译语言 脚本语言 c c python 题目出现编译语
  • 智能运维 VS 传统运维|AIOps服务管理解决方案全面梳理

    云智慧 AIOps 社区是由云智慧发起 针对运维业务场景 提供算法 算力 数据集整体的服务体系及智能运维业务场景的解决方案交流社区 该社区致力于传播 AIOps 技术 旨在与各行业客户 用户 研究者和开发者们共同解决智能运维行业技术难题 推
  • java开发Demo~微信扫码支付,java开发示例

    开发所需工具类 以上工具类以上传到我的资源 下载地址 http download csdn net download han xiaoxue 10184832 开发所需jar 具体的代码不贴了 说明下PayConfigUtil中的参数 AP
  • CMake详细使用

    1 CMake简介 CMake是一个用于管理源代码的跨平台构建工具 可以方便地根据目标平台和编译工具产生对应的编译文件 主要用于C C 语言的构建 但是也可以用于其它编程语言的源代码 如同使用make命令工具解析Makefile文件一样 c
  • 百度群组链接分享 - 铁人圈子

    百度网盘群组链接分享 铁人圈子 铁人圈子 tierenpan com 是一个分享百度网盘群组的发布平台 可以在铁人圈子上实时分享你的群组链接 并且和其他网友互动交流分享资源 群组分享 百度群组链接分享 地址 https www tieren
  • 58道Vue常见面试题集锦,涵盖入门到精通

    1 vue优点 答 轻量级框架 只关注视图层 是一个构建数据的视图集合 大小只有几十 kb 简单易学 国人开发 中文文档 不存在语言障碍 易于理解和学习 双向数据绑定 保留了 angular 的特点 在数据操作方面更为简单 组件化 保留了
  • vue 项目首页加载速度优化以及解决首页白屏问题

    前言 最近再接手一个vue项目的时候 公司运营部就说首页加载要10秒以上时间 这谁能忍受 老板也说时间太久 技术部老大说之前的同事优化过一次 时间还是这么久 重担就落在我身上了 于是我就开始着手优化 最终的结果呢就是优化到了2秒以内加载出来
  • python中dtype的使用规范_Python numpy.dtype() 使用实例

    The following are code examples for showing how to use They are extracted from open source Python projects You can vote