zoukankan      html  css  js  c++  java
  • numpy学习笔记

    1. numpy切片和整型数组访问

    (1)
    a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])


    b = a[1,:] b.shape = (4,), b = [1,2,3,4]
    c = a[1:2, :], c.shape = (1,4), c = [[1,2,3,4]]

    (2)
    数组下标,可以使用数组来表示
    a = np.array([[1,2], [3, 4], [5, 6]])
    print a[[0, 1, 2], [0, 1, 0]]  # Prints "[1 4 5]"
    print np.array([a[0, 0], a[1, 1], a[2, 0]]) # Prints "[1 4 5]"

    a = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])

    # Create an array of indices
    b = np.array([0, 2, 0, 1])
    
    # Select one element from each row of a using the indices in b
    print a[np.arange(4), b]  # Prints "[ 1  6  7 11]"
    
    # Mutate one element from each row of a using the indices in b
    a[np.arange(4), b] += 10
    
    print a  # prints "array([[11,  2,  3],
             #                [ 4,  5, 16],
             #                [17,  8,  9],
             #                [10, 21, 12]])
     


  • 相关阅读:
    vue
    手写Promise
    Promise应用
    Promise
    JS_URL模块
    模板字符串应用
    JS-OOP
    jQuery——过时,但是经典,关注核心点即可。
    MySql补充
    offset系列
  • 原文地址:https://www.cnblogs.com/shadowwalker9/p/7629972.html
Copyright © 2011-2022 走看看