python 创建类cell数组
来源:互联网 发布:php调用百度日历api 编辑:程序博客网 时间:2024/06/16 20:11
When you do this:
a = np.array([[np.array([[2, 2]]), np.array([[3, 3]])]])
the final call to np.array actually concatenates the inner two, so you get one array at the end:
>>> aarray([[[[2, 2]], [[3, 3]]]])>>> a.shape(1, 2, 1, 2)
But to mimic a cell array you want to basically have an array of arrays. You can acheive this by setting dtype=object, but you must create the array and set the elements separately to avoid the automatic merging.
three = array([[array([[2, 2, 2]]), array([[3, 3]])]])two = np.empty(three.shape, dtype=object)two[0,0,0] = np.array([[2,2]])two[0,1,0] = np.array([[3,3]])
Then:
sio.savemat('two.mat', {'two': two})
to see what they look like:
>>> twoarray([[[array([[2, 2]])], [array([[3, 3]])]]], dtype=object)>>> two.shape(1, 2, 1)
Note that I may have gotten confused about your desired shape, since you have so many nested brackets, so you might have to reshape some of this, but the idea should hold regardless.
例如:
npose = 5nsmile = 2poseSmile_cell = np.empty((npose,nsmile),dtype=object)for i in range(5): for k in range(2): poseSmile_cell[i,k] = np.zeros((4,4))print poseSmile_cell.shape
参考文献:
https://stackoverflow.com/questions/19797822/creating-matlab-cell-arrays-in-python
阅读全文
0 0
- python 创建类cell数组
- Python创建二维数组
- python创建二维数组
- python 创建二维数组
- python中创建数组
- Python创建二维数组
- python创建数组
- python中数组的创建
- Python创建动态二维数组
- python-如何创建二维数组
- Python二维数组的创建
- Python创建数组的坑
- Python中创建二维数组
- 自定义cell代码创建
- 创建自定义cell
- matlab cell数组
- matlab的cell数组
- MATLAB Cell数组
- 这是我的第一篇csdn博客
- [Android][第一行代码][第 8 章 多媒体]
- 欢迎使用CSDN-markdown编辑器
- AIX下更换rootvg磁盘与DIAG工具定位故障磁盘
- 全屏设置
- python 创建类cell数组
- redis持久化的配置
- EditPlus_3.4及注册码
- php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法
- 【bzoj2648&bzoj2716】[Violet 3]天使玩偶&SJY摆棋子【kd树】
- C#读取文件夹的所有文件
- Angular <select> 和<radio> ngModel 绑定
- 面试智力题
- Android实现无序树形结构图,类似思维导图和级联分层图(无序,随机位置)