问题标签 [numpy-dtype]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - 在 dtype 中构造具有重叠字段的 np.array
我有一个 dtype 如下:
现在,我可以写:
我想添加一个xy
字段以使其更易于使用。我可以这样做:
但是,现在我不能再使用以前的方法构造数组,而不得不求助于:
这是危险的重复。
有什么方法可以将属性标记为彼此的别名,这样我就不必处理这个了?
python - 如何从其他 dtypes 创建一个 numpy dtypes?
我通常会像这样创建 numpy dtypes:
但是在我的代码中,我还使用了这些字段a
并b
在其他地方单独使用:
为了可维护性,我想C
从类型中派生出来A
,并且B
以某种方式是这样的:
numpy 有没有办法通过组合其他 dtypes 来创建复杂的 dtypes?
python - 在使用 numpy.genfromtxt 创建的 ndarray 中插入列
ndarray
我使用 txt 文件创建了一个numpy.genfromtxt
. txt 文件如下所示:
我正在运行读取数据:
我现在正在尝试复制第 4 列(我调用的那一列V
)并将其放置在其自身之后(在最后一T
列之前)。
我知道我可以通过 复制该列data['V']
,但是如何将此副本放在V
和T
(第 4 列和第 5 列)之间?我看了看numpy.insert
,但我不确定如何指定索引(obj
参数)。我尝试了numpy.insert(data_copy, data_copy['T'],data_copy['V'])
没有运气(我收到了IndexError: index 61 is out of bounds for size 20
)。
python - Select type with higher precision
Function common_precision
takes two numpy arrays, say x
and y
. I want to make sure that they are in the same and the highest precision. It seems that relational comparison of dtypes does something to what I want, but:
- I don't know what it actually compares
- It thinks that
numpy.int64
<numpy.float16
, which I'm not sure if I agree
Edited:
Thanks to kennytm's answer I found that NumPy's find_common_type
does exactly what I wanted.
python - Scipy:更改插值的dtype
是否可以强制 scipy 的插值输出具有特定 numpy dtype 的数组?
例如,从 scipy.interpolate.Rbf() 输出一个 float32 数组?
python - 如何从 numpy dtype 获取 C 类型定义字符串
我正在开发一个 C 代码生成器。给定一个 numpydtype
实例,如何获取对应的 C 类型定义字符串?理想情况下用纯 python 完成。
例如:
当然,手动实现这一点并不难。然而,在做跨平台的事情时,“官方”的方式会更安全、更省事。
python - numpy 中类似 str 的输入的默认 dtype 是什么?
我只是想确认字符串的默认数据类型是否是unicode
在创建ndarray
. 我找不到任何明确说明这一点的参考资料。可能是太明显了,不需要说明。
指定 dtype 时:
不指定 dtype:
此外,当指定 dtype 时,字面b
量表示什么。根据文档,它表明bool
这里似乎不是这种情况。
有人可以澄清一下吗?
python - 为什么在 NumPy 中使用地板除法时会显示 dtype(即使它是本机类型)?
通常,dtype
当它等同于本机类型时,它是隐藏的:
但不知何故,这不适用于地板除法或模数:
为什么有区别?
Python 3.5.4、NumPy 1.13.1、Windows 64 位
python-2.7 - Pandas DataFrame - 在 whos dtype=='category' 列上聚合会导致性能下降
我使用具有高内存使用率的大数据帧,我读到如果我更改重复值列上的 dtype,我可以节省大量内存。
我试过了,它确实将内存使用量降低了 25%,但后来我遇到了我无法理解的性能缓慢。
我在 dtype 'category' 列上进行分组聚合,在更改 dtype 之前大约需要 1 秒,更改之后大约需要 1 分钟。
此代码演示了 2 倍的性能下降:
我试图理解的是这种缓慢的原因是什么,以及是否有办法克服它。
谢谢!
python - numpy 包含多个 dtype 时如何确定数组数据类型?
我正在尝试使用 numpy,当使用内置方法 dtype 时,我发现了以下数据类型。按照我得到的几个结果。你能解释一下u11是什么意思吗
o/p = >U11