|
val = np.array(var.value).reshape(-1,) |
Current code:
val = np.array(var.value).reshape(-1,)
Proposed replacement:
val = np.array(var.value).ravel()
Both reshape(-1,) and ravel() flatten arrays into 1-D.
Benchmarks show that ravel() consistently outperforms reshape(-1,), because it is optimized for flattening and avoids extra shape compatibility checks.
ravel() is also more robust: it returns a view whenever possible and only falls back to a copy if required, while reshape(-1,) requires the array to be contiguous.