擅长:python、mysql、java
<p>不确定这是您想要的,但是来自<code>hypothesis.extra.numpy</code>的<code>arrays</code>似乎没有复制值的选项</p>
<p>您可以这样构造所需的阵列:</p>
<pre><code>import numpy as np
from hypothesis.strategies import integers
strat = integers(10, -10)
np.array([[x, x] for x in [strat.example() for _ in range(4)]], np.int16)
</code></pre>
<p>示例结果:</p>
<pre class="lang-none prettyprint-override"><code>array([[-9, -9],
[ 0, 0],
[-2, -2],
[ 0, 0]], dtype=int16)
</code></pre>
<p>如果您不喜欢<code>2</code>维度被烘焙,您可以使用如下两个参数:</p>
<pre><code>def get_array(rows, cols, strat):
np.array([[x]*cols for x in [strat.example() for _ in range(rows)]], np.int16)
get_array(4, 2, integers(-10, 10))
</code></pre>