码迷,mamicode.com
首页 > 编程语言 > 详细

numpy_数组(三个点,无冒号,单冒号,双冒号)

时间:2018-06-21 15:33:54      阅读:1402      评论:0      收藏:0      [点我收藏+]

标签:import   遍历   color   imp   style   array   numpy   索引   port   

import numpy
>>> a = numpy.array([[1,2,3,4,5],[6,7,8,9,10],[1,2,3,4,5],[6,7,8,9,10]])
>>> a
array([[ 1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10],
       [ 1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10]])
>>> a[...,2]
array([3, 8, 3, 8])
>>> a[...,:2]
array([[1, 2],
       [6, 7],
       [1, 2],
       [6, 7]])
>>> a[...,::2]
array([[ 1,  3,  5],
       [ 6,  8, 10],
       [ 1,  3,  5],
       [ 6,  8, 10]])
>>> a[...,:3]
array([[1, 2, 3],
       [6, 7, 8],
       [1, 2, 3],
       [6, 7, 8]])
>>> a[...,::3]
array([[1, 4],
       [6, 9],
       [1, 4],
       [6, 9]])

a[...,2]:...表示遍历每行,2表示索引为2的所在列。

a[...,:2]:...表示遍历每行,:2表示索引为<2的0,1所在的列。

a[...,::2]:...表示遍历每行,2表示步长,选取多索引为0,2,4所在的列。

numpy_数组(三个点,无冒号,单冒号,双冒号)

标签:import   遍历   color   imp   style   array   numpy   索引   port   

原文地址:https://www.cnblogs.com/liuxuanhe/p/9209090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!