I've never seen a colon used in this way in python and need an explanation.
Here dim
, in_features
, and out_features
are all int. i
is the index counter in a for loop. When I use dim:(i + 1)
on it's own it doesn't throw an error, but also doesn't do anything. If I use 0:(i+1)
on it's own i get a SyntaxError: illegal target for annotation
.
A reproducible snippet is below.
dim = 8
in_features = dim
hidden_dim = 3
out_features = dim * hidden_dim
weight = np.zeros([out_features, in_features])
for i in range(dim):
weight[i * out_features // dim:(i + 1) * out_features // dim,\
0:(i + 1) * in_features // dim] \
= np.random.uniform(size=[out_features // dim, (i + 1) * in_features // dim])