<p dir="auto">A bit random, but I just read some style guidelines of a larger python project which suggested to use</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="arr.shape = (100, 10)
# Instead of:
arr = arr.reshape(100, 10)"><pre class="notranslate"><span class="pl-s1">arr</span>.<span class="pl-s1">shape</span> <span class="pl-c1">=</span> (<span class="pl-c1">100</span>, <span class="pl-c1">10</span>)
<span class="pl-c"># Instead of:</span>
<span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">arr</span>.<span class="pl-en">reshape</span>(<span class="pl-c1">100</span>, <span class="pl-c1">10</span>)</pre></div>
<p dir="auto">I very much dislike this use, because the ndarray container should be considered immutable IMO. It also is practically pretty useless, the <strong>only</strong> gain is that you implicetely add an assertion:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="arr = arr.reshape(100, 10)
assert arr.base is not None"><pre class="notranslate"><span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">arr</span>.<span class="pl-en">reshape</span>(<span class="pl-c1">100</span>, <span class="pl-c1">10</span>)
<span class="pl-k">assert</span> <span class="pl-s1">arr</span>.<span class="pl-s1">base</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span></pre></div>
<p dir="auto">Assuming you don't actually want to have the side effect of changing the shape of the array at another place as well (which maybe is reasonable in very rare cases, but horrifies me a bit).</p>
<p dir="auto">Anyway, reading that suggestion, I think it really is time that we add a <code class="notranslate">copy=None</code> kwarg, so that you can do <code class="notranslate">arr = arr.reshape(100, 10, copy=False)</code> (or <code class="notranslate">copy=True</code>) to be explicit about it without modifying the container.<br>
The only reason that never happened, is because we already have <code class="notranslate">Reshape</code> and <code class="notranslate">NewShape</code> functions in the <code class="notranslate">C-API</code>. Frankly, thats annoying, but for all I care it would be a good start to just add it to the python API without changing the C level one.</p>
<p dir="auto">Inspired by my discussion with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/charris/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/charris">@charris</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="262224136" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/9810" data-hovercard-type="pull_request" data-hovercard-url="/numpy/numpy/pull/9810/hovercard" href="https://github.com/numpy/numpy/pull/9810">#9810</a>, I would like to propose adding an optional <code class="notranslate">copy</code> argument to <code class="notranslate">np.reshape()</code> and <code class="notranslate">ndarray.reshape()</code>.</p>
<p dir="auto">Proposed semantics:</p>
<ul dir="auto">
<li><code class="notranslate">copy=None</code>: copy only if necessary (default).</li>
<li><code class="notranslate">copy=True</code>: always copy.</li>
<li><code class="notranslate">copy=False</code>: never copy. Raise an error if the data cannot be reshaped without a copy.</li>
</ul>
<p dir="auto">This would allow users to ensure desired behavior for <code class="notranslate">reshape</code> and alleviate the primary use case for modifying <code class="notranslate">ndarray.shape</code>.</p>