栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

numpy学习(2)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

numpy学习(2)

import numpy as np

t1 = np.arange(12)
print(t1.shape)

t2 = t1.reshape(3, 4)
print(t2)
print(t2.shape)

# [[[ 0  1  2  3]
#   [ 4  5  6  7]
#  [ 8  9 10 11]]
#
# [[12 13 14 15]
#  [16 17 18 19]
# [20 21 22 23]]]
# 2 代表数据块,3 代表每一块的数据行;4 代表每一块的数据列
t5 = np.arange(24).reshape(2, 3, 4)
print(t5)

t6 = t5.reshape(4, 6)
t7 = t5.reshape(24)
t8 = t5.reshape(24, 1)
t9 = t5.reshape(1, 24)
print(t5)
print(t6)
print(t7)
print(t8)
print(t9)

# 计算数组中的元素个数
print(t5.shape[0])
print(t5.shape[1])
print(t5.shape[2])
count = t5.shape[0] * t5.shape[1] * t5.shape[2]
print(count)
t10 = t5.reshape(count)
print(t10)

# 把多维数组转换成一维数组
t11 = t5.flatten()
print(t11)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/314114.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号