Replaced rank with ndim to avoid numpy deprecation warning