Python Numpy Tutorials: 数组--3
来源:互联网 发布:天猫与淘宝的盈利方式 编辑:程序博客网 时间:2024/06/03 17:16
# -*- coding: utf-8 -*-"""Python Version: 3.5Created on Thu May 11 11:18:49 2017E-mail: Eric2014_Lv@sjtu.edu.cn@author: DidiLv"""import numpy as npa = np.array([[1,2], [3, 4], [5, 6]])# An example of integer array indexing.# The returned array will have shape (3,) and print(a[[0, 1, 2], [0, 1, 0]]) # Prints "[1 4 5]"# The above example of integer array indexing is equivalent to this:print(np.array([a[0, 0], a[1, 1], a[2, 0]])) # Prints "[1 4 5]"# 这里会发现上述两种方式提取的值是一样的,同理如下,不多赘述# When using integer array indexing, you can reuse the same# element from the source array:print(a[[0, 0], [1, 1]]) # Prints "[2 2]"# Equivalent to the previous integer array indexing exampleprint(np.array([a[0, 1], a[0, 1]])) # Prints "[2 2]"# Create a new array from which we will select elementsa = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])print a # prints "array([[ 1, 2, 3], # [ 4, 5, 6], # [ 7, 8, 9], # [10, 11, 12]])"# Create an array of indicesb = np.array([0, 2, 0, 1])# Select one element from each row of a using the indices in bprint(a[np.arange(4), b]) # Prints "[ 1 6 7 11]"# Mutate one element from each row of a using the indices in ba[np.arange(4), b] += 10print(a) # prints "array([[11, 2, 3], # [ 4, 5, 16], # [17, 8, 9], # [10, 21, 12]])
0 0
- Python Numpy Tutorials: 数组--3
- Python Numpy Tutorials: 数组
- Python Numpy Tutorials: 数组--1
- Python Numpy Tutorials: 数组--2
- Python Numpy Tutorials: 数组--4
- Python Numpy Tutorials: 改变数组的维度
- Python Numpy Tutorials: 集合
- Python Numpy Tutorials: 函数
- Python Numpy Tutorials: 类
- Python Numpy Tutorials: 数据类型
- Python Numpy Tutorials: Broadcasting
- Python Numpy Tutorials: 元组
- Python Numpy Tutorials: 数组乘法:点乘和矩阵(数组)乘法
- Python Numpy Tutorials: 数组中数学函数及变形(reshape)
- Python Scipy&NUmpy Tutorials:Scipy与Matplot
- Python Numpy数组保存
- Python Numpy数组保存
- Python Numpy数组保存
- 贪心算法基础之聪明的工匠 hunnu OJ 10611 acm,huffman算法思想
- iOS Label大小不变内容可适应变化(字体大小变化)
- interface_cast做什么的?
- 该公众号暂时无法提供服务,请稍后再试
- Linux驱动开发———平台总线设备驱动
- Python Numpy Tutorials: 数组--3
- Recaman's Sequence
- sendmessage和getcomponents
- 欢迎使用CSDN-markdown编辑器
- NSInvocation crash
- Hadoop-2.6.5集群安装配置
- TI am335xD用到的数据手册及板级文件
- virtualbox centos7 minimal 开发环境安装,网络配置与宿主机共享文件夹设置
- 一键部署openstack