You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
<p>array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)</p>
|
|
<p>Create an array.</p>
|
|
<h4 class="heading">See Also</h4>
|
|
empty, empty_like, zeros, zeros_like, ones, ones_like, fill<h4 class="heading">Examples</h4>
|
|
<pre class="rst-doctest-block">
|
|
>>> np.array([1, 2, 3])
|
|
array([1, 2, 3])
|
|
</pre>
|
|
<p>Upcasting:</p>
|
|
<pre class="rst-doctest-block">
|
|
>>> np.array([1, 2, 3.0])
|
|
array([ 1., 2., 3.])
|
|
</pre>
|
|
<p>More than one dimension:</p>
|
|
<pre class="rst-doctest-block">
|
|
>>> np.array([[1, 2], [3, 4]])
|
|
array([[1, 2],
|
|
[3, 4]])
|
|
</pre>
|
|
<p>Minimum dimensions 2:</p>
|
|
<pre class="rst-doctest-block">
|
|
>>> np.array([1, 2, 3], ndmin=2)
|
|
array([[1, 2, 3]])
|
|
</pre>
|
|
<p>Type provided:</p>
|
|
<pre class="rst-doctest-block">
|
|
>>> np.array([1, 2, 3], dtype=complex)
|
|
array([ 1.+0.j, 2.+0.j, 3.+0.j])
|
|
</pre>
|
|
<p>Data-type consisting of more than one element:</p>
|
|
<pre class="rst-doctest-block">
|
|
>>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])
|
|
>>> x['a']
|
|
array([1, 3])
|
|
</pre>
|
|
<p>Creating an array from sub-classes:</p>
|
|
<pre class="rst-doctest-block">
|
|
>>> np.array(np.mat('1 2; 3 4'))
|
|
array([[1, 2],
|
|
[3, 4]])
|
|
</pre>
|
|
<pre class="rst-doctest-block">
|
|
>>> np.array(np.mat('1 2; 3 4'), subok=True)
|
|
matrix([[1, 2],
|
|
[3, 4]])
|
|
</pre>
|