Python: ndarray operation

本文介绍了Python中NumPy库的核心数据类型ndarray的高效使用方法,包括如何快速读取矩阵的部分索引、如何对ndarray进行翻转操作及错误处理,并展示了两个ndarray合并的具体方式。

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

Ndarray is most used data type in python, because many modules such as pylab, numpy use ndarray as default data type to undertake matrix operation. So using ndarray type of data will quickly accelerate the speed of python calculation.

  • Read part of indices from an ndarray matrix
    Suppose we have a matrix in ndarray type as M: 10*20, X:10, if we just wish to get the first dimension of this matrix we can set the code like this:
    M[0:3,:].shape=(3,20)
    X[0:3].shape=(3)
    The index begin with 0 end with 2, the last index 3 is not included!

  • reorder ndarray matrix
    x=numpy.array([0,1,2,3])
    y=numpy.array([[0,1,2,3],[0,2,4,6]])
    xf=numpy.fliplr(x)
    error Input must be >=2-d, this error might suggest that function fliplr can only work on matrix whose dimension bigger or equal than 2
    yf=array([][3,2,1,0],[6,4,2,0])

  • combine two ndarray
    A=numpy.concatenate([A1,A2])

转载于:https://www.cnblogs.com/docnan/p/7157788.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值