implementing custom aggregation functions in NumPy's np.apply_along_axis causing TypeError
I'm having a hard time understanding I'm collaborating on a project where Hey everyone, I'm running into an issue that's driving me crazy. I'm working on a personal project and I'm trying to use `np.apply_along_axis` to apply a custom function that computes the geometric mean to each row of a 2D NumPy array... However, I'm working with a `TypeError` that says 'need to multiply an array of shape (0,) with an array of shape (N,)', which I believe stems from how I'm handling edge cases in empty rows. Here's a simplified version of my code: ```python import numpy as np from scipy.stats import gmean def custom_geometric_mean(arr): if arr.size == 0: return 0 # handle empty case return gmean(arr) # Sample data with an empty row data = np.array([[1, 2, 3], [4, 5, 6], []]) # Applying the function along axis 1 (rows) result = np.apply_along_axis(custom_geometric_mean, 1, data) print(result) ``` The behavior occurs because the empty row causes the `custom_geometric_mean` function to be called with an empty array, which I thought I could handle with the size check. Here's the behavior I'm getting: ``` TypeError: need to multiply an array of shape (0,) with an array of shape (N,) ``` I'm using NumPy version 1.23.1 and SciPy version 1.9.0. What am I missing? How can I effectively manage the aggregation when dealing with empty sub-arrays in `np.apply_along_axis`? I'd really appreciate any guidance on this. This is part of a larger CLI tool I'm building. Thanks in advance! I'm working with Python in a Docker container on Windows 10. What's the correct way to implement this? I recently upgraded to Python 3.11. My development environment is Debian. Is there a better approach?