numpy数组(一)

import numpy as ny

a = ny.array([1, 2, 3, 4])
b = ny.array([5, 6, 7, 8])
c = ny.array([[1, 2, 3, 4], [2, 3, 4, 3], [4, 5, 6, 7]])
d = ny.array([[1, 2, 3], [2, 3, 4, 3], [4, 5, 6, 7]])
# 数组的形状可以通过其shape 属性获得,它是一个描述数组各个轴长度的元组(tuple):
print('a.shape:  ', a.shape)
print('c.shape:  ', c.shape)
print('d.shape   ', d.shape)  # 不等的时候宽度无法获取
c.shape = 4, 3
print('after change c:  ', c)
# 当设置某个轴的元素个数为-1 时,将自动计算此轴的长度。
c.shape = 2, -1
print('after change c:  ', c)
# 使用数组的 reshape()方法,
# 可以创建指定形状的新数组,而原数组的形状保持不变:
e = a.reshape((2, 2))
print('e:  ', e)
print('a:  ', a)
# 数组 e 和a 其实共享数据存储空间,因此修改其中任意一个数组
# 的元素都会同时修改另外一个数组的内容
a[0] = 100
print('after change a:  ', a)
print('after change e:  ', e)
# 数组的元素类型可以通过 dtype 属性获得
print('c.type:  ', c.dtype)
# 可以通过dtype 参数在创建数组时指定元素类型,
# 注意 float 是 64 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值