qu...@gmx.at wrote: > i have to reshape a matrix beta of the form (4**N, 4**N, 4**N, 4**N) > into betam like (16**N, 16**N) following: > > betam = np.zeros((16**N,16**N), dtype = complex) > for k in xrange(16**N): > ind1 = np.mod(k,4**N) > ind2 = k/4**N > for l in xrange(16**N): > betam[k,l] = beta[np.mod(l,4**N), l/4**N, ind1 , ind2] > > is there a smarter/faster way of getting the above done?
no time to check if this is what you want, but is this it? a = np.arange((4**(4*N))).reshape(4**N,4**N,4**N,4**N) b = a.reshape((16**N, 16**N)) If that doesn't do it right, you may be able to mess with the strides, etc. do some googling, and check out: numpy.lib.stride_tricks -Chris > for N=2, that already takes 0.5 seconds but i intend to use it > for N=3 and N=4 ... > > thanks for your input, > q > -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion