python - NumPy, .reshape()
问题描述
这段代码有什么作用?
climate_results = np.concatenate((climate_data, yields.reshape(1000, 1)), axis=1)
注意:我有一个名为气候数据和产量的变量
解决方案
numpy.concatenate()
, 连接两个数组。
(在您的代码中,气候数据有 1000 行,在此示例中,气候数据有 2 行,我们应该重塑为可以连接两个数组的 1000 或 2 行) 请参阅此示例:
climate_data = np.array([[1,2],[3,4]])
# array([[1, 2],
# [3, 4]])
yields = np.array([0,1])
# array([0, 1])
yields = np.array([0,1]).reshape(2,1)
# array([[0],
# [1]])
climate_results = np.concatenate((climate_data, yields.reshape(2, 1)), axis=1)
climate_results
输出:
array([[1, 2, 0],
[3, 4, 1]])
您可以axis=0
像下面这样连接:
climate_data = np.array([[1,2],[3,4]])
yields = np.array([[0,1]])
# array([[0, 1]])
climate_results = np.concatenate((climate_data, yields), axis=0)
输出:
array([[1, 2],
[3, 4],
[0, 1]])
推荐阅读
- bookdown - 为什么我不能再更新我的 bookdown 书?
- accessibility - 使 server.R 将 HTML 代码插入网页
- html - 在 HTML 和 Angular dart 中,有没有办法根据函数改变元素的样式?
- c++ - 在 C++ 中,在库之间转换相似类的最佳方法是什么?
- r - 为什么 PCA geom_point 形状包含未指定的因素?
- python - 生成最多 d 个不匹配的所有排列
- python - Python 请求:下载数据:image/jpeg;base64
- python - Python subprocess.communicate stderrdata 不打印
- mesh - 从非结构化网格重采样标量场到矩形网格
- javascript - XMLHttpRequest 意外返回通信错误