np.reshape()函数,np.flatten()

#注意reshape((2,3))里面要加括号, Returns an array containing the same data with a new shape.

#reshape函数不是对原地操作,有返回值

import numpy as np

# 新建一个二维列表
t1 = np.array([[1, 2, 3], [4, 3, 4]])
print(t1.shape)

# 新建一个一维度列表,并更改数值
t2 = np.arange(24).reshape(6, 4)
print(t2.shape)
print(t2)

# 改为三维数组(2, 3, 4):2个模块,3行,每行4列
t3 = np.arange(24).reshape((2, 3, 4))
print(t3.shape)
print(t3)

# 将不确定维度的数组变为,一维度,方法1
print(t3.shape[0])
t3 = t3.reshape((t3.shape[0] * t3.shape[1] * t3.shape[2]))
print(t3)
# 将不确定维度的数组变为,一维度,方法2
t4 = np.arange(10).reshape((2, 5))
print(t4)
t4 = t4.flatten()
print(t4)
# 数组加常数,会在所有元素中加上数
t5 = np.arange(10).reshape((2, 5))
t5 = t5 + 1
print(t5)

# nan格式数据,not a number,inf格式数据,表示infinity,无穷的意思
t6 = np.arange(10).reshape((2, 5))
t6 = t6 / 0
print(t6)

#!!!!数组的加减乘除,为对应数上加减乘除, 维度不同时候,会广播计算
#!!!!! ,只要在任何情况下,有形状相同,都可以进行计算!!!!!!,

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贾世林jiashilin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值