问题标签 [genfromtxt]

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.

0 投票
1 回答
300 浏览

python - 使用来自 2 个数据集的数据绘制多个图

我有一个名为“data.rei”的数据集和另一个名为“gages.txt”的数据集。'data.rei' 包含数据,'gages.txt' 包含我想与数据链接的位置 ID 信息和日期/时间。我想绘制这些,每个位置 1 个图表,包括 x 轴上的日期和 y 轴上的测量值和建模值。

data.rei 的格式如下:

gages.txt 如下:

到目前为止,这是我的脚本:

但是,我收到错误消息:

0 投票
1 回答
816 浏览

numpy - numpy 函数 IOError

在我运行 OSX Mavericks 的 macbook air 上(我几乎可以肯定前几天在运行几乎相同代码的运行 Windows 7 的 PC 上不会发生这种情况)以下代码给了我以下错误。

massfile 按预期打印出来'Users/BigD/Dropbox/PhD/PPMS/DATA/DB/HeatCap/HeatCapMass.txt'

但我得到了错误

它似乎试图使用路径的一半,然后将完整路径文件添加到它的末尾。

有谁知道为什么会发生这种情况或可以建议解决方法?

0 投票
2 回答
190 浏览

python - 在 python 中将文本文件作为数组或列表打开

我正在尝试在 python 中将文本文件作为数组或列表打开。该文件如下所示。
此外,这里是文本文件的链接。
ftp://rammftp.cira.colostate.edu/demaria/ebtrk/ebtrk_atlc.txt

我曾尝试使用 NumPy genfromtxt,但它返回错误,因为它无法判断 100100 是两列中的两个元素。它将其视为列中的一个条目,因此返回错误,指出每行中的列数不匹配。

有没有办法解决这个问题?谢谢

0 投票
1 回答
2038 浏览

python - Genfromtxt 文件名

我正在尝试读取作为字符串存储在数据文件中的文件名。那里没问题。如果我将它传递给 genfromtxt,我会收到错误“IOError: Z:\Python\Rb input.txt not found”。如果我将文件名明确放入 genfromtxt 中,它可以工作

这失败并出现错误“IOError: Z:\Python\Rb input.txt not found.”

但他的作品

2个打印语句给出

现在似乎与传递字符串有关-请提供任何建议

0 投票
1 回答
461 浏览

python - the dtype parameter in numpy genfromtxt

I am trying to create MX2 numpy matrix or array from the following file contents:

I have come across the genfromtxt() function but have been unsuccessful in extracting my data. With a file called f I tried the following: ts = genfromtxt(f, delimiter=",") and got an array filled all with nan. This was only a first attempt, so I read the documentation about the dtype parameter which specifies the data-type of the array. It appears that to get an MX2 matrix with entries of the form (datetime, int) I would have the following: dtype=[('f1', datetime64), ('f2', uint)]. When I did this, I got the following assigned to variable ts:

Every value I got for the matrix is some constant... Why did it not read from my file? Obviously this is not the output that I should get.

How do I get the desired MX2 matrix or array with the first column being the datetime and the second column being an integer as shown with the head command?

0 投票
3 回答
13264 浏览

python - genfromtxt() 中的 NumPy dtype 问题,将字符串读取为字节串

我想将标准 ascii csv 文件读入 numpy,它由浮点数和字符串组成。

例如,

无论我尝试什么,生成的数组看起来像

例如,

但是,我想为字节字符串转换保存一个步骤,并且想知道如何直接将字符串列作为常规字符串读取。

我从 numpy.genfromtxt() 文档中尝试了几件事,例如dtype='S,S,S,f,S'or dtype='a25,a25,a25,f,a25',但这里没有任何帮助。

我很害怕,但我想我只是不明白 dtype 转换是如何工作的......如果你能在这里给我一些提示会很好!

谢谢

0 投票
2 回答
890 浏览

python - 使用 loadtxt (numpy) 读取缺少数据的文件

当我尝试阅读以下数据时:

我有一个错误。
然后我尝试使用以下方法完成这些丢失的数据:

但我得到了这个错误:

Line #31112 (got 7 columns instead of 8)

我想用nan或类似的东西填充缺失的数据。

我在一个名为的 ascii 文件中有这样的数据RSTN

当我这样做时:

我收到了这个错误:

0 投票
1 回答
549 浏览

python - 使用 numpy 导入多个文本文件

我一直在导入多个 txt 文件并使用它们来创建绘图。代码与以前相同,但这次似乎不起作用。我已经把它带回了基础,我不知道出了什么问题。

我只需要循环中说明的列,因为 txt 文件有多个值。这将返回:

任何帮助,将是太棒了!

0 投票
1 回答
272 浏览

python - 是否可以更改从 genfromtxt 创建的 numpy 数组中仅一列的类型?

我正在创建一个 numpy 数组,然后将其导出到 django 模型中。作为 dtype 属性,我有一个 None,但我有一列应该是一个允许 NULL 值的整数。现在,当在 csv 中找到一个“NULL”字符串时,该列的类型在 bool 中发生了变化,它不接受 None。

现在,是否有可能dtype={'name of the columns', 'int'}只为该列做一些事情,让其余的仍然在 None 上,让 numpy 决定类型?

0 投票
2 回答
4585 浏览

python - numpy genfromtxt 转换器未知的列数

我有几个数据数字文件,其中小数点分隔符是逗号。所以我使用 lambda 函数进行转换:

文件中的数据是这样的:

在我的函数decimal_converter中,我需要指定我的文件包含的列数。通常我不需要指定numpy.genfromtxt文件中的列数,它会占用它找到的所有内容。即使使用转换器选项,我也想保留此功能。