Pandas
df[('Cat','apple'), level=[0,2])
df.loc[('Cat',slice('food', 'water'), 'apple')]
import numpy as np
# Sample data
N = 100000
x = np.random.uniform(size=N)
y = np.random.uniform(size=N)
# Calculate z
z = np.sqrt(x**2 + y**2)
# Mask condition: keep elements where z <= 1
condition = z <= 1
# Use boolean indexing to filter elements that meet the condition
filtered_z = z[condition]
#if you want to set the element to 0 when they meet the condition
z[condition]=0