[Python] Accessing Array Elements

NumPy Reference: Indexing

Note: Indexing starts at 0 (zero).

 

复制代码
def slicing():
    a = np.random.rand(5,4)
    print(a)
    """
    [[ 0.15372787  0.83347785  0.86855635  0.23592008]
    [ 0.74925447  0.08453883  0.62021973  0.51972556]
    [ 0.33835541  0.03772665  0.53220179  0.2095391 ]
    [ 0.41991738  0.76028856  0.22081936  0.4240198 ]
    [ 0.93666236  0.72688287  0.99309427  0.69388106]]
    """
    print(a[0:2, 0:4:3]) #0:4:3 X:Y:Z, if Y > Z, z is step, so here is take columns from [0,4), step is 3
    """
   [[ 0.15372787 0.23592008] [ 0.74925447 0.51972556]]
"""
if __name__ == "__main__": slicing()
复制代码

 

posted @   Zhentiw  阅读(212)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2016-12-18 [React Native] Animate Styles of a React Native View with Animated.timing
2016-12-18 [Compose] 10. Capture Side Effects in a Task
2015-12-18 [Unit Testing] Node testing: Test api Get request
2015-12-18 [CSS3] Interactive Pseudo-Classes :link :visited :hover :active
2015-12-18 [Javascript] Intro to Recursion - Refactoring to a Pure Function
2015-12-18 [Javascript ] Array methods in depth - sort
点击右上角即可分享
微信分享提示