MCPcopy Create free account
hub / github.com/numpy/numpy / reshape

Function reshape

numpy/array_api/_manipulation_functions.py:56–76  ·  view source on GitHub ↗

Array API compatible wrapper for :py:func:`np.reshape `. See its docstring for more information.

(x: Array, 
            /, 
            shape: Tuple[int, ...],
            *,
            copy: Optional[Bool] = None)

Source from the content-addressed store, hash-verified

54
55# Note: the optional argument is called 'shape', not 'newshape'
56def reshape(x: Array,
57 /,
58 shape: Tuple[int, ...],
59 *,
60 copy: Optional[Bool] = None) -> Array:
61 """
62 Array API compatible wrapper for :py:func:`np.reshape <numpy.reshape>`.
63
64 See its docstring for more information.
65 """
66
67 data = x._array
68 if copy:
69 data = np.copy(data)
70
71 reshaped = np.reshape(data, shape)
72
73 if copy is False and not np.shares_memory(data, reshaped):
74 raise AttributeError("Incompatible shape for in-place modification.")
75
76 return Array._new(reshaped)
77
78
79def roll(

Callers 2

vector_normFunction · 0.70
test_reshape_copyFunction · 0.50

Calls 3

reshapeMethod · 0.80
_newMethod · 0.80
copyMethod · 0.45

Tested by 1

test_reshape_copyFunction · 0.40