博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
numpy 矩阵形状调整:拉伸、变成一位数组
阅读量:4211 次
发布时间:2019-05-26

本文共 287 字,大约阅读时间需要 1 分钟。

#coding:utf-8import numpy as np## 改变数组的形状#将b 变成3*4 的矩阵b=np.arange(24).reshape(3,8)print(b)#将多维数组变成 1维数组a=b.ravel()print(a)#将多维数组变成 1维数组,faltten 返回的是真实的数组,需要分配新的内存空间。而ravel 返回的是数组的视图print(b.flatten())print("拉直之后:",b)#改变 b 本身的数组,会改变所作用的数组b.resize(2,12)#不改变b  本身的数组c=b.reshape(2,12)print(c)

转载地址:http://lrgli.baihongyu.com/

你可能感兴趣的文章
【IOS游戏开发】之测试发布(Distribution)
查看>>
【IOS游戏开发】之IPA破解原理
查看>>
【一天一道LeetCode】#45. Jump Game II
查看>>
【一天一道LeetCode】#46. Permutations
查看>>
【一天一道LeetCode】#47. Permutations II
查看>>
【一天一道LeetCode】#48. Rotate Image
查看>>
【一天一道LeetCode】#56. Merge Intervals
查看>>
【一天一道LeetCode】#57. Insert Interval
查看>>
【一天一道LeetCode】#58. Length of Last Word
查看>>
【一天一道LeetCode】#59. Spiral Matrix II
查看>>
【一天一道LeetCode】#30. Substring with Concatenation of All Words
查看>>
【一天一道LeetCode】#60. Permutation Sequence.
查看>>
【一天一道LeetCode】#113. Path Sum II
查看>>
【一天一道LeetCode】#114. Flatten Binary Tree to Linked List
查看>>
【unix网络编程第三版】阅读笔记(二):套接字编程简介
查看>>
【一天一道LeetCode】#115. Distinct Subsequences
查看>>
【一天一道LeetCode】#116. Populating Next Right Pointers in Each Node
查看>>
【一天一道LeetCode】#117. Populating Next Right Pointers in Each Node II
查看>>
【一天一道LeetCode】#118. Pascal's Triangle
查看>>
【一天一道LeetCode】#119. Pascal's Triangle II
查看>>