Smart handling of Python array with many indices -
i have following piece of code:
p1 = np.array([[[[[[[[[[0.]*2]*2]*2]*2]*2]*2]*2]*2]*2]*2) s = [0]*10 # # s # p1[s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9]] += 1 is there smarter way of:
- creating p1 without brackets, and
- access components of p1 string or list?
i have in mind like:
p1[s] += 1 or:
p1[*s] += 1 for example, if instead of 10 indices wanted n indices?
np.array([[[[[[[[[[0.]*2]*2]*2]*2]*2]*2]*2]*2]*2]*2) is better written as:
np.zeros((2,2,2,2,2,2,2,2,2,2)) or there ten 2s:
np.zeros((2,)*10)
Comments
Post a Comment