I would do it like this, where (a, b) is the center of your mask:
import numpy as np
a, b = 1, 1
n = 7
r = 3
y,x = np.ogrid[-a:n-a, -b:n-b]
mask = x*x + y*y <= r*r
array = np.ones((n, n))
array[mask] = 255
More Related Contents:
- What are the advantages of NumPy over regular Python lists?
- ValueError: setting an array element with a sequence
- Numpy `logical_or` for more than two arguments
- What is the difference between contiguous and non-contiguous arrays?
- How to copy a 2D array into a 3rd dimension, N times?
- How do I convert a numpy array to (and display) an image?
- How does NumPy’s transpose() method permute the axes of an array?
- How do I print the full NumPy array, without truncation?
- Multiplying across in a numpy array
- initialize a numpy array
- numpy array assignment problem
- Preserve custom attributes when pickling subclass of numpy array
- What does dtype=object mean while creating a numpy array?
- Python Numpy TypeError: ufunc ‘isfinite’ not supported for the input types
- Why is a `for` over a Python list faster than over a Numpy array?
- Selecting close matches from one array based on another reference array
- Input and output numpy arrays to h5py
- Why does numpy have a corresponding function for many ndarray methods?
- Numpy sub-array assignment with advanced, mixed indexing
- Efficiently sorting a numpy array in descending order?
- Numpy: Divide each row by a vector element
- Setting the fmt option in numpy.savetxt
- Access n-th dimension in python [duplicate]
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- How does the axis parameter from NumPy work?
- numpy – evaluate function on a grid of points
- Shift rows of a numpy array independently
- Interweaving two NumPy arrays efficiently
- Formatting floats in a numpy array [duplicate]
- How to convert a 3d numpy array to 2d