Skip to content

Instantly share code, notes, and snippets.

@FrancescAlted
Last active September 12, 2022 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrancescAlted/9fbfe7a953b3b092cdd1ff63cdd61856 to your computer and use it in GitHub Desktop.
Save FrancescAlted/9fbfe7a953b3b092cdd1ff63cdd61856 to your computer and use it in GitHub Desktop.
@udf.scalar()
def circle_filter(val: udf.float32, row: udf.int64, col: udf.int64,
nrows: udf.int64, ncols: udf.int64) -> udf.float32:
x = (2. * row / nrows) - 1.
y = (2. * col / ncols) - 1.
if ((x ** 2 + y ** 2) <= 1) and val >= 0.5:
return 1.
return math.nan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment