简体   繁体   English

如何将Numpy数组值分配给其他变量

[英]How to assign Numpy array values to other variable

This is my code: 这是我的代码:

y_predForThisMatchType = model.predict(X_test, num_iteration=model.best_iteration)
print(type(y_predForThisMatchType))
y_predForThisMatchType = y_predForThisMatchType.reshape(-1)
print(type(y_predForThisMatchType))

count = 0
for i in range (len(y_pred)):
    if y_pred.loc[i]  == abType:
        y_pred.loc[i] = y_predForThisMatchType[count]
        count = count + 1

Output: 输出:

class 'numpy.ndarray' 类'numpy.ndarray'

class 'numpy.ndarray' 类'numpy.ndarray'

/opt/conda/lib/python3.6/site-packages/pandas/core/indexing.py:189: SettingWithCopyWarning: /opt/conda/lib/python3.6/site-packages/pandas/core/indexing.py:189:SettingWithCopyWarning:

A value is trying to be set on a copy of a slice from a DataFrame 试图在DataFrame的切片副本上设置一个值

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self._setitem_with_indexer(indexer, value) 请参阅文档中的警告: http ://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self._setitem_with_indexer(索引器,值)

Python just print the above output, and that's all. Python只是打印上面的输出,仅此而已。 The program is technically running, but below code do not get executed, no real error is shown. 该程序在技术上正在运行,但是下面的代码未执行,未显示实际错误。

Error Line: y_pred.loc[i] = y_predForThisMatchType[count] 错误线: y_pred.loc[i] = y_predForThisMatchType[count]

y_pred variable is a pandas dataframe. y_pred变量是一个熊猫数据y_pred

Have you checked your outputs completely? 您是否已经完全检查了输出?
In my experience, your code is working. 以我的经验,您的代码正在运行。
The display is just a warning and can be disabled with: 该显示仅是警告,可以通过以下方式禁用:

pandas.options.mode.chained_assignment = None  # default='warn'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM