Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec18892

Browse files
committed
FIX: allow reshape 2-D to return a bare 1-d list
1 parent 9f74ea7 commit ec18892

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,11 @@ def _reshape_2D(X, name):
13971397
# 1D array of scalars: directly return it.
13981398
return [X]
13991399
elif X.ndim in [1, 2]:
1400-
# 2D array, or 1D array of iterables: flatten them first.
1401-
return [np.reshape(x, -1) for x in X]
1400+
if hasattr(X[0], '__len__'):
1401+
# 2D array, or 1D array of iterables: flatten them first.
1402+
return [np.reshape(x, -1) for x in X]
1403+
else:
1404+
return [X]
14021405
else:
14031406
raise ValueError("{} must have 2 or fewer dimensions".format(name))
14041407

0 commit comments

Comments
 (0)