zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    使用Notepad++进行php开发所必需的插件
    jquery操作复选框(checkbox)的12个小技巧总结
    深入理解拆箱
    史上最全UML的详细解析
    我理解的invoke和begininvoke
    java中的冒泡排序算法
    java中的选择排序算法
    Java实现将json中的数值插入到mysql中
    Java实现对mysql中的数值进行读取、插入、更新、删除
    Java连接MySQL数据库
  • 原文地址:https://www.cnblogs.com/xkxf/p/8262170.html
Copyright © 2011-2022 走看看