I was multiplying two numpy arrays:
import numpy as np
X = np.random.randn(4500,3500)
v = np.random.randn(3500,200)
Both of them are C_CONTIGUOUS by default:
X.flags
# C_CONTIGUOUS : True
v.flags
# C_CONTIGUOUS : True
And the multiplication is fast:
%timeit X @ v
# 41 ms ± 2.54 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
However, if I reverse X array than something weird happens:
%timeit X[::-1,::-1] @ v
# 3.97 s ± 54.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Questions:
- This post says that reversion operation creates a view. The resulting view is neither C_CONTIGUOUS nor F_CONTIGUOUS. What does it mean ?
X[::-1,::-1].flags
# C_CONTIGUOUS : False
# F_CONTIGUOUS : False
- Why the reversion operation slows down multiplication so badly ?