程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[...,1] and [...,1:2] in python

編輯:Python

A[...,1] and a[...,1:2] are often used in array calls>

 1 import tensorflow as tf2 import numpy as np3 a = np.array([[[1,2,21],[3,4,34]],[[5,6,56],[7,8,78]]])4 print('a.shape:',a.shape)56 b = a[...,0:2]7 print('b:',b)8 print('shape.b:',b.shape)

The results are as follows:

a.shape: (2, 2, 3)b : [[[1 2][3 4]][[5 6][7 8]]]shape.b: (2, 2, 2)

But if a[...,1] is used, the result is as follows:

a.shape: (2, 2, 3)b : [[2 4][6 8]]shape.b: (2, 2)

You can see that [...,1:3] represents the number of 1:3 in the last dimension, the input is the array of the last dimension in the original dimension, and [...,2] isThe information in the -2 dimension, the input is one dimension less than the original dimension.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved