arrays - 我可以在同一轴的数组中添加超过 1 个维度吗?
问题描述
我没有正确理解尺寸/轴的概念。我尝试了以下代码:
import numpy as np
l = [1,2,3,4,5,6]
x = np.expand_dims(l,0)
print(x)
print(x.shape)
x = np.expand_dims(l,0)
print(x)
print(x.shape)
结果我得到:
[[1 2 3 4 5 6]]
(1, 6)
[[1 2 3 4 5 6]]
(1, 6)
为什么我没有得到:
[[1 2 3 4 5 6]]
(1, 6)
[[[1 2 3 4 5 6]]]
(1, 1, 6)
解决方案
您需要在第二次尝试扩展尺寸时更改l
为:x
x = np.expand_dims(l,0)
x = np.expand_dims(x,0)
print(x.shape)
(1, 1, 6)
推荐阅读
- c++ - 推力::sort_by_key 上的配置参数无效
- javascript - appendChild 到 h2 类
- php - laravel 类 'Gloudemans\Shoppingcart\ShoppingcartServiceProvider' 未找到
- javascript - 禁用拖放
- python - 子进程的信号处理程序和coverage.py的atexit
- veins - 如何更改 Veins-LTE 中的消息频率
- sockets - 为什么 PrintWriter 不工作?
- json - 使用 Apache Camel + Jetty 组件的 GET 请求
- html - 为什么文本框和按钮在不同的屏幕上看起来不布局?
- r - 如何在 agricolae 包中进行事后测试,Tukey?