尝试将_fields()附加到数据数组,没有错误,但没有发生任何事情

2024-10-02 22:23:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将一个新列附加到数组中,没有错误,但什么也没有发生。。。能告诉我我做错了什么吗

import numpy as np
from numpy.lib import recfunctions
from numpy.lib.recfunctions import append_fields

#the_array = np.genfromtxt(file.csv, ...) dimensions 170 rows, 25 columns

jrows = np.ma.size(the_array)
the_field = np.zeros(jrows)
the_field[:] = 391
append_fields(the_array, 'minute', data = the_field)

#no errors, but nothing appended.

Tags: thefromimportnumpyfieldfieldslibas
1条回答
网友
1楼 · 发布于 2024-10-02 22:23:00

NumPy中几乎没有任何内容会改变现有阵列的结构append_fields返回一个新的数组,您可以忽略并丢弃该数组。这确实应该在文档中提到,但是文档目前没有列出返回值,这使得它看起来像是一个变异函数

无论如何,不要忽略返回值:

new_array = append_fields(the_array, 'minute', data=the_field)

相关问题 更多 >