Skip to content

FAQ: how to resolve: TypeError: reshape() takes 2 positional arguments but 3 were given

András Retzler edited this page Oct 29, 2022 · 4 revisions

TL;DR the correct way to call reshape is something.reshape(tuple_with_shape). In MATLAB we are used to reshape(what,size1,size2) but the Python convention is what.reshape((size1,size2)).

>>> d
DM(
[[5, 6], 
 [7, 8]])


>>> d.reshape(4,1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: reshape() takes 2 positional arguments but 3 were given

>>> d.reshape((4,1))
DM([5, 7, 6, 8])
Clone this wiki locally