python3 numpy学习

本文介绍了Numpy库的基本使用,包括数组创建、数学运算和数据类型转换。Numpy提供快速的数学计算能力,支持各种数值类型,并允许进行类型转换。通过`help(numpy)`或`help(np.doc.TOPIC)`获取更多帮助。示例中展示了创建不同类型的数组,如`np.float32`、`np.int_`和`np.uint8`,并演示了如何用`astype`方法改变数组元素的数据类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.引用

import numpy as np
核心功能:

  1. 任意同类项的数组对象
  2. 数组上的快速数学运算
  3. 线性代数、傅立叶变换、随机数生成

2. 帮助获取

  1. 方式1
    python3
    import numpy
    help(numpy)

  2. 方式2
    from numpy import doc
    help(doc)
    he following topics are available:

    • basics
    • broadcasting
    • byteswapping
    • constants
    • creation
    • glossary
    • indexing
    • internals
    • misc
    • structured_arrays
    • subclassing
    • ufuncs

    You can view them by
    help(np.doc.TOPIC)

3. basics

基础数据类型

  • Numpy type C type Description

  • np.bool bool Boolean(True or False) stored as a byte

  • np.byte signed char Platform-defined

  • np.ubyte unsigned char

  • np.short short

  • np.ushort unsigned short

  • np.intc int

  • np.uintc unsigned int

  • np.int_ long

  • np.uint unsigned long

  • np.longlong long long

  • np.ulonglong unsigned long long

  • np.half np.float16

  • np.single float

  • np.double double

  • np.longdouble long double

  • np.csingle float complex

  • np.cdouble double complex

  • np.clongdouble long double complex

  • np.int8 int8_t

  • np.int16 int16_t

  • np.int32 int32_t

  • np.int64 int64_t

  • np.uint8 uint8_t

  • np.uint16 uint16_t

  • np.uint32 uint32_t

  • np.uint64 uint64_t

  • np.float32 float

  • np.float64 double

  • np.complex64 float complex

  • np.complex12 double complex

import numpy as np
x=np.float32(1.0)
x
1.0

y=np.int_([1,2,4])
y
array([1,2,4]

z=np.arange(3, dtype=np.uint8)
z
array([0,1,2], dtype=uint8)

np.array([1,2,3], dtype=‘f’)
array([1., 2., 3.], dtype=float32_

修改类型

z=np.arange(3, dtype=np.uint8)
z.astype(float)
np.int8(z)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值