python - 将 numpy 数组从 [1,2,3,4] 重塑为 [[1],[2],[3],[4]]
问题描述
我想重塑
[1,2,3,4]
进入:
[[1],[2],[3],[4]]
有没有简单的 numpy 方法来做到这一点?
解决方案
利用
reshaped_arr = arr.reshape(4,1)
测试一下:
import numpy as np
arr = np.arange(4)
reshaped_arr = arr.reshape(4,1)
print (reshaped_arr)
输出:
[[0]
[1]
[2]
[3]]
推荐阅读
- intellij-plugin - Intellij Compound 和 Multirun 插件的限制和挑战
- angular - 在 IE10 中将日历更改为法语的问题
- java - 不使用 FXML 从另一个类访问 Javafx 元素
- wordpress - 如何在古腾堡 wordpress 中创建自定义嵌入块
- sql - 有没有办法确保 WHERE 子句在 DISTINCT 之后发生?
- c++ - rdtsc乱序执行的解决方案?
- java - 数字日期格式
- angular - 当使用异步管道在 NGXS 存储中更改状态时,Angular 组件不会重新评估
- sql - 过滤视图时如何利用基础索引?
- c# - 我需要使用 xpath 在我的 HTML 中获取没有标签的文本