簡體   English   中英

下面代碼中的“t[..., :1]”是什么意思?

[英]What does " t[..., :1] " in below code means?

這是上下文:

def normal_scale_uncertainty(t, softplus_scale=0.05):
    """Create distribution with variable mean and variance"""
    ts = t[..., :1]
    return tfd.Normal(loc = ts,
                      scale = 1e-3 + tf.math.softplus(softplus_scale * ts))

簡短回答...替換多個:

長答案:讓我們看一個例子。

In [20]: d = np.array([[[i + 2*j + 8*k for i in range(5)] for j in range(4)] for k in range(3)])                        

In [21]: d.shape                                                                                                        
Out[21]: (3, 4, 5)

In [22]: d[:, :, 0]                                                                                                     
Out[22]: 
array([[ 0,  2,  4,  6],
       [ 8, 10, 12, 14],
       [16, 18, 20, 22]])

In [23]: d[..., 0]                                                                                                      
Out[23]: 
array([[ 0,  2,  4,  6],
       [ 8, 10, 12, 14],
       [16, 18, 20, 22]])

In [24]: d[:, :, 0] == d[..., 0]                                                                                        
Out[24]: 
array([[ True,  True,  True,  True],
       [ True,  True,  True,  True],
       [ True,  True,  True,  True]])

您可以使用d[0, ..., 0]d[0, ...]嗎? 你可以。 d[..., 0, ...]呢? 你會得到一個錯誤: IndexError: an index can only have a single ellipsis ('...')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM