How to implement guide with np.concatenate on arrays with incompatible shapes in numpy 1.24
I'm prototyping a solution and I'm working with an scenario when using `np.concatenate` to join multiple arrays that have incompatible shapes. Specifically, I'm trying to concatenate two 2D arrays, one of shape `(3, 4)` and another of shape `(3, 5)`, which I expected to throw an behavior, but instead, I get a confusing `ValueError` about mismatched dimensions. Hereβs the code I used: ```python import numpy as np a = np.random.rand(3, 4) # shape (3, 4) b = np.random.rand(3, 5) # shape (3, 5) # Attempt to concatenate result = np.concatenate((a, b), axis=1) ``` When I run this code, I receive the following behavior: ``` ValueError: all the input array dimensions for the concatenation axis must match exactly. ``` I understand that the shapes donβt align for concatenation along `axis=1`, but I expected to catch this before attempting to concatenate. I've also tried checking the shapes using `a.shape` and `b.shape` beforehand, which both return the expected values. What am I missing here? Is there a better way to handle such cases while working with arrays in NumPy? How can I efficiently manage mismatched dimensions without running into this sort of runtime behavior? I'm working with Python in a Docker container on Linux. Thanks in advance! I'm working in a Debian environment. Any advice would be much appreciated.