def checkerboard(shape):
return np.indices(shape).sum(axis=0) % 2
Most compact, probably the fastest, and also the only solution posted that generalizes to n-dimensions.
More Related Contents:
- ValueError: setting an array element with a sequence
- Numpy `logical_or` for more than two arguments
- Converting numpy dtypes to native python types
- Concatenate a NumPy array to another NumPy array
- ImportError: numpy.core.multiarray failed to import
- Fast replacement of values in a numpy array
- Link ATLAS/MKL to an installed Numpy
- Recursive definitions in Pandas
- Integer overflow in numpy arrays
- Most efficient way to reverse a numpy array
- numpy is already installed with Anaconda but I get an ImportError (DLL load failed: The specified module could not be found)
- How to specify upper and lower limits when using numpy.random.normal
- Python Numpy TypeError: ufunc ‘isfinite’ not supported for the input types
- What is the inverse of the numpy cumsum function?
- TensorFlow ValueError: Cannot feed value of shape (64, 64, 3) for Tensor u’Placeholder:0′, which has shape ‘(?, 64, 64, 3)’
- Find index where elements change value numpy
- Subtracting numpy arrays of different shape efficiently
- Why is np.where faster than pd.apply
- 2d convolution using python and numpy
- save numpy array in append mode
- Converting a 2D numpy array to a structured array
- Numpy sub-array assignment with advanced, mixed indexing
- Numpy difference between neighboring elements
- new pythonic style for shared axes square subplots in matplotlib?
- How to shade region under the curve in matplotlib
- Randomly select from numpy array
- Can’t import cv2; “DLL load failed”
- A numpy array unexpectedly changes when changing another one despite being separate
- Computing cross-correlation function?
- Numpy `ValueError: operands could not be broadcast together with shape …`