Skip to content

Commit 5254479

Browse files
committed
ENH: Optimize performance of np.atleast_1d
1 parent f34dac4 commit 5254479

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

numpy/_core/shape_base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ def atleast_1d(*arys):
6060
(array([1]), array([3, 4]))
6161
6262
"""
63+
if len(arys) == 1:
64+
result = asanyarray(arys[0])
65+
if result.ndim == 0:
66+
result = result.reshape(1)
67+
return result
6368
res = []
6469
for ary in arys:
65-
ary = asanyarray(ary)
66-
if ary.ndim == 0:
67-
result = ary.reshape(1)
68-
else:
69-
result = ary
70+
result = asanyarray(ary)
71+
if result.ndim == 0:
72+
result = result.reshape(1)
7073
res.append(result)
71-
if len(res) == 1:
72-
return res[0]
73-
else:
74-
return tuple(res)
74+
return res
7575

7676

7777
def _atleast_2d_dispatcher(*arys):

0 commit comments

Comments
 (0)