• Python笔记 #07# NumPy 文档地址 & Subsetting 2D Arrays


      文档地址:np.array()  

    1、<class 'numpy.ndarray'>

    ndarray 表示 n 维度(n D)数组 (= n 行数组)。

    2、打印 array 结构 —— np_array.shape

    3、Subsetting 2D Arrays 的两种方式

    不管是 arr[1][2] 还是 arr[1,2] 都是可行的,不过教程推荐第二种方式。

     

    4、代码演示 & 一个取子集的小技巧

    创建:

    # Create baseball, a list of lists
    baseball = [[180, 78.4],
                [215, 102.7],
                [210, 98.5],
                [188, 75.2]]
    
    # Import numpy
    import numpy as np
    
    # Create a 2D numpy array from baseball: np_baseball
    np_baseball = np.array(baseball)
    
    # Print out the type of np_baseball
    print(type(np_baseball))
    
    # Print out the shape of np_baseball
    print(np_baseball.shape)

    打印结构:

    # baseball is available as a regular list of lists
    
    # Import numpy package
    import numpy as np
    
    # Create a 2D numpy array from baseball: np_baseball
    np_baseball =  np.array(baseball)
    
    # Print out the shape of np_baseball
    print(np_baseball.shape)

     小技巧:

    # baseball is available as a regular list of lists
    
    # Import numpy package
    import numpy as np
    
    # Create np_baseball (2 cols)
    np_baseball = np.array(baseball)
    
    # Print out the 50th row of np_baseball
    print(np_baseball[49,:])
    
    # Select the entire second column of np_baseball: np_weight
    np_weight = np_baseball[:,1]
    
    # Print out height of 124th player
    print(np_baseball[123,0])

     5、整体数学运算

    # baseball is available as a regular list of lists
    # updated is available as 2D numpy array
    
    # Import numpy package
    import numpy as np
    
    # Create np_baseball (3 cols)
    np_baseball = np.array(baseball)
    
    # Print out addition of np_baseball and updated
    print(np_baseball + updated)
    
    # Create numpy array: conversion
    conversion = np.array([0.0254, 0.453592, 1])
    
    # Print out product of np_baseball and conversion
    print(conversion * np_baseball)
  • 相关阅读:
    go语言从零学起(三) -- chat实现的思考
    go语言从零学起(二)--list循环删除元素(转载)
    go语言从零学起(一) -- 文档教程篇
    Spring框架事务支持模型的优势
    Thymeleaf
    社保到底是多交好,还是少交好?
    使用静态工厂方法而不是构造器
    EJB、RMI、XMLRPC、Hessian、Thrift 、Protobuf
    MySQL存储过程
    MySQL常用功能语句分类总结
  • 原文地址:https://www.cnblogs.com/xkxf/p/8262170.html
Copyright © 2020-2023  润新知