{"id":1070,"date":"2026-10-02T19:06:09","date_gmt":"2026-10-02T19:06:09","guid":{"rendered":"https:\/\/www.askpython.com\/?p=1070"},"modified":"2026-10-04T17:38:53","modified_gmt":"2026-10-04T17:38:53","slug":"python-numpy-arrays","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python-modules\/numpy\/python-numpy-arrays","title":{"rendered":"NumPy Arrays in Python: Create Arrays with np.array()"},"content":{"rendered":"<!-- article-type: tutorial -->\n<!-- receipt-backed-first-person -->\n\n<p class=\"wp-block-paragraph\">Python lists can hold numbers, but doing math on every element means writing a loop. A NumPy array stores numbers of one type in a grid, so you can calculate on the whole array at once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here I&#8217;ll create arrays from Python lists with <code>np.array()<\/code>, and explain how shape and dtype describe them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a NumPy array?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A NumPy array is an indexed collection of values with a shape and a shared data type. NumPy names its array class ndarray, meaning an N-dimensional array, so the same class can represent a sequence or a table of numbers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An axis is a direction along which you index the array. For a rectangular table, the first axis selects a row and the second selects a column, with indexing starting at zero. The shape records the length of each axis.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Input<\/th><th>Shape<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>10<\/td><td>()<\/td><td>A scalar array with no axes<\/td><\/tr><tr><td>[10, 20, 30]<\/td><td>(3,)<\/td><td>A sequence along one axis<\/td><\/tr><tr><td>[[1, 2, 3], [4, 5, 6]]<\/td><td>(2, 3)<\/td><td>A table with two rows and three columns<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The dtype describes how each element is represented, such as an integer or a floating-point number. A numeric array uses one dtype throughout, so NumPy can apply arithmetic to its elements without a Python loop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/numpy.org\/doc\/stable\/user\/absolute_beginners.html\" target=\"_blank\" rel=\"noopener\">NumPy beginner guide<\/a> connects this model to indexing and calculations. An array of Python objects is a separate case, because its elements reference objects rather than storing a dense grid of numeric values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use a Python environment with NumPy installed, and run the samples from the directory containing that environment. I ran the examples with Python 3.14.7 and NumPy 2.5.3 on Linux, using a fresh virtual environment.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need Python with the venv module and permission to create a project directory.<\/li>\n\n\n<li>You should recognize Python lists and function calls before converting the values.<\/li>\n\n\n<li>The commands use a Linux or macOS shell and require network access for installation.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Create the environment in your project directory and install NumPy through that environment&#8217;s interpreter, so installation and script execution use the same Python.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\npython3 -m venv .venv\n.\/.venv\/bin\/python -m pip install --upgrade numpy\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Each Python example includes its own import, so you can save it as the filename given beside the code and run it independently. The alias np is the conventional short name for NumPy, not another package you need to install.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Convert a Python list into an array<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pass a flat list to np.array() to create an array with one axis. Save this example as flat_array.py, keeping the Python list and the returned array in separate variables so you can see where conversion happens.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\nvalues = &#x5B;10, 20, 30]\nflat = np.array(values)\nprint(flat)\nprint(&quot;shape:&quot;, flat.shape)\nprint(&quot;dimensions:&quot;, flat.ndim)\nprint(&quot;dtype:&quot;, flat.dtype)\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">NumPy prints [10 20 30], without commas between the elements, but the array still contains separate numbers. The shape is (3,), and ndim is 1 because the flat input has one axis. NumPy inferred int64 for these Python integers in the tested environment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The trailing comma in (3,) is Python&#8217;s notation for a tuple containing one item, not an extra dimension. To reproduce the displayed result, run the saved file from your project directory.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n.\/.venv\/bin\/python flat_array.py\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"482\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/flat-output.png\" alt=\"NumPy flat array output with shape (3,), one dimension and dtype int64\" class=\"wp-image-71763\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/flat-output.png 1920w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/flat-output-300x75.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/flat-output-1024x257.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/flat-output-768x193.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/flat-output-1536x386.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><figcaption>The flat input produces one axis, with its length shown in shape.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Passing a tuple instead of a list also creates an array from a sequence, as documented in the <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.array.html\" target=\"_blank\" rel=\"noopener\">np.array() reference<\/a>. Passing a single number creates a scalar array with shape (), so use a surrounding list when you need a length-one sequence.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Build rows with an explicit dtype<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For a rectangular array, pass nested lists whose rows have equal lengths. The example&#8217;s rows become a numeric table, and dtype=np.float32 converts the integer inputs into single-precision floating-point values during construction.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\nrows = &#x5B;&#x5B;1, 2, 3], &#x5B;4, 5, 6]]\ngrid = np.array(rows, dtype=np.float32)\nprint(grid)\nprint(&quot;shape:&quot;, grid.shape)\nprint(&quot;size:&quot;, grid.size)\nprint(&quot;dtype:&quot;, grid.dtype)\nprint(&quot;row 1, column 2:&quot;, grid&#x5B;1, 2])\nprint(&quot;doubled:&quot;, (grid * 2).tolist())\n\nmixed = np.array(&#x5B;1, 2.5])\nprint(&quot;mixed:&quot;, mixed.tolist(), mixed.dtype)\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The outer list supplies two rows, and each inner list supplies three columns, giving shape (2, 3). The size attribute counts all six elements. Indexing grid[1, 2] selects the last value in the second row and prints 6.0.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Expression<\/th><th>Observed result<\/th><th>Reason<\/th><\/tr><\/thead><tbody><tr><td>grid.dtype<\/td><td>float32<\/td><td>The constructor receives an explicit dtype<\/td><\/tr><tr><td>(grid * 2).tolist()<\/td><td>[[2.0, 4.0, 6.0], [8.0, 10.0, 12.0]]<\/td><td>Multiplication applies to each element<\/td><\/tr><tr><td>mixed.dtype<\/td><td>float64<\/td><td>NumPy chooses a common type for the integer and decimal<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Multiplication produces a result array here, so grid keeps its original values. The .tolist() calls convert results into Python lists for a comma-separated display, without changing the arrays they came from.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Choose the dtype to match the next operation&#8217;s range and precision requirements, rather than assuming that conversion preserves every input exactly. float32 uses less precision than float64, and an integer dtype can&#8217;t retain a fractional component. NumPy&#8217;s <a href=\"https:\/\/numpy.org\/doc\/stable\/user\/basics.creation.html\" target=\"_blank\" rel=\"noopener\">array-creation guide<\/a> documents the conversion and range boundaries.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Control which arrays share data<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">np.array() copies input data by default, and np.asarray() can reuse a compatible existing ndarray. That choice changes what happens after assignment to an element, even when both arrays initially print the same values.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\nsource = np.array(&#x5B;10, 20, 30], dtype=np.float32)\nreused = np.asarray(source, dtype=np.float32)\nindependent = np.array(source)\nconverted = np.asarray(source, dtype=np.float64)\nprint(&quot;reuses source:&quot;, reused is source)\nprint(&quot;copy shares memory:&quot;, np.shares_memory(independent, source))\nprint(&quot;converted shares memory:&quot;, np.shares_memory(converted, source))\n\nreused&#x5B;0] = 99\nprint(&quot;source:&quot;, source.tolist())\nprint(&quot;independent:&quot;, independent.tolist())\n\nsequence = np.arange(6)\nreshaped = sequence.reshape(2, 3)\nprint(&quot;shapes:&quot;, sequence.shape, reshaped.shape)\nprint(&quot;reshape shares memory:&quot;, np.shares_memory(sequence, reshaped))\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">I changed reused[0] to 99, and source printed [99.0, 20.0, 30.0]. The independent array still printed [10.0, 20.0, 30.0], because its numeric data occupies separate storage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the matching dtype, reused is source returns True, meaning both names refer to the same object. Requesting float64 requires conversion, so converted doesn&#8217;t share source&#8217;s numeric storage. The <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.asarray.html\" target=\"_blank\" rel=\"noopener\">np.asarray() reference<\/a> also documents copying when a requested layout requires it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A view is an array object that refers to another array&#8217;s data buffer. Basic slicing returns a view, so changing a sliced element can change the original array. Call .copy() when a numeric slice must be edited independently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reshaping changes how dimensions organize the elements, and the new dimensions must account for the original element count. The contiguous sequence above has six values, so reshape(2, 3) succeeds and shares its data. sequence itself keeps shape (6,).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.reshape.html\" target=\"_blank\" rel=\"noopener\">reshape reference<\/a> permits a copy when the requested arrangement can&#8217;t be represented as a view. To extend the experiment, change an element through reshaped and inspect sequence, then repeat with an explicit copy before editing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Numeric storage independence doesn&#8217;t imply that an object array recursively copies its Python objects, as NumPy&#8217;s <a href=\"https:\/\/numpy.org\/doc\/stable\/user\/basics.copies.html\" target=\"_blank\" rel=\"noopener\">copy-and-view guide<\/a> explains. For other ways to duplicate an array, continue with AskPython&#8217;s <a href=\"https:\/\/www.askpython.com\/python-modules\/numpy\/copy-a-numpy-array-into-another-array\">array-copying walkthrough<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the shapes and storage choices<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To reproduce the constructor checks together, save the following as numpy_array_examples.py. It prints the attributes beside their inputs and catches the expected ragged-input error so the remaining checks can finish.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\nflat = np.array(&#x5B;10, 20, 30])\nprint(&quot;flat:&quot;, flat)\nprint(&quot;flat shape:&quot;, flat.shape, &quot;dimensions:&quot;, flat.ndim, &quot;dtype:&quot;, flat.dtype)\ngrid = np.array(&#x5B;&#x5B;1, 2, 3], &#x5B;4, 5, 6]], dtype=np.float32)\nprint(&quot;grid:&quot;, grid.tolist())\nprint(&quot;grid shape:&quot;, grid.shape, &quot;size:&quot;, grid.size, &quot;dtype:&quot;, grid.dtype)\nmixed = np.array(&#x5B;1, 2.5])\nprint(&quot;mixed values:&quot;, mixed.tolist(), &quot;dtype:&quot;, mixed.dtype)\nsource = np.array(&#x5B;10, 20, 30], dtype=np.float32)\nprint(&quot;asarray reuses input:&quot;, np.asarray(source, dtype=np.float32) is source)\nprint(&quot;array shares input memory:&quot;, np.shares_memory(np.array(source), source))\ntry:\n    np.array(&#x5B;&#x5B;1, 2], &#x5B;3]])\nexcept ValueError as error:\n    print(&quot;ragged numeric input:&quot;, type(error).__name__)\nobjects = np.array(&#x5B;&#x5B;1, 2], &#x5B;3]], dtype=object)\nprint(&quot;object-array shape:&quot;, objects.shape)\nprint(&quot;object-array row types:&quot;, type(objects&#x5B;0]).__name__, type(objects&#x5B;1]).__name__)\nsequence = np.arange(6)\nreshaped = sequence.reshape(2, 3)\nprint(&quot;reshape:&quot;, sequence.shape, &quot;to&quot;, reshaped.shape)\nprint(&quot;reshape shares input memory:&quot;, np.shares_memory(sequence, reshaped))\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The identity check asks whether np.asarray() returns the source object, and np.shares_memory() asks whether two arrays overlap in storage. Those questions are distinct, because a view can be a different object that still shares data.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n.\/.venv\/bin\/python numpy_array_examples.py\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"978\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/09\/numpy-array-examples.png\" alt=\"NumPy terminal output showing array shapes, dtypes, copy behavior, a ragged-input error, and reshape memory sharing\" class=\"wp-image-67315\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/09\/numpy-array-examples.png 1920w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/09\/numpy-array-examples-300x153.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/09\/numpy-array-examples-1024x522.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/09\/numpy-array-examples-768x391.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/09\/numpy-array-examples-1536x782.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><figcaption>The constructor checks show rectangular shapes, numeric dtypes and memory-sharing decisions.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The flat integer dtype shown here is the observed result for this environment, so inspect your array&#8217;s dtype when its width matters. Explicit float32 construction doesn&#8217;t depend on guessing the default integer width.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When array construction rejects the input<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Unequal row lengths can&#8217;t form the rectangular numeric table used above. Save this diagnostic as array_errors.py to compare that failure with a deliberately chosen object array and an integer that exceeds the requested dtype&#8217;s range.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\ntry:\n    np.array(&#x5B;&#x5B;1, 2], &#x5B;3]])\nexcept ValueError as error:\n    print(type(error).__name__ + &quot;:&quot;, error)\n\nobjects = np.array(&#x5B;&#x5B;1, 2], &#x5B;3]], dtype=object)\nprint(&quot;object shape:&quot;, objects.shape)\nprint(&quot;row types:&quot;, type(objects&#x5B;0]).__name__, type(objects&#x5B;1]).__name__)\n\ntry:\n    np.array(&#x5B;128], dtype=np.int8)\nexcept OverflowError as error:\n    print(type(error).__name__ + &quot;:&quot;, error)\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The ragged numeric input raises ValueError, with a message describing an inhomogeneous shape. For this input, dtype=object produces shape (2,), with a Python list at each position. It doesn&#8217;t produce a two-column numeric matrix.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To see the full diagnostic and the object-array result, run the saved file. The exception handlers print the errors and allow the script to continue, so a successful process exit here doesn&#8217;t mean the rejected conversions succeeded.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n.\/.venv\/bin\/python array_errors.py\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"606\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/input-errors.png\" alt=\"NumPy unequal row ValueError, object array shape and int8 OverflowError\" class=\"wp-image-71764\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/input-errors.png 1920w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/input-errors-300x95.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/input-errors-1024x323.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/input-errors-768x242.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2026\/10\/input-errors-1536x485.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><figcaption>Unequal rows reject numeric construction, and the int8 conversion rejects 128.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Requirement<\/th><th>Action<\/th><th>Boundary<\/th><\/tr><\/thead><tbody><tr><td>Numeric matrix calculations<\/td><td>Make all rows the same length<\/td><td>Choose any padding value according to its meaning in the calculation<\/td><\/tr><tr><td>Rows that grow separately<\/td><td>Keep a Python list of lists<\/td><td>Appending to a list doesn&#8217;t require rebuilding a numeric array<\/td><\/tr><tr><td>Array of Python objects<\/td><td>Select dtype=object deliberately<\/td><td>Nested structure still affects shape inference<\/td><\/tr><tr><td>Integer 128<\/td><td>Choose an integer dtype with sufficient range<\/td><td>Signed int8 ends at 127<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;d keep independently growing rows as lists until a calculation needs a rectangular array, because choosing object dtype doesn&#8217;t resolve what the different row lengths mean.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The int8 example raises OverflowError because 128 is outside its representable range. Check the required range before choosing a smaller integer dtype, and distinguish a constructor&#8217;s range check from overflow during arithmetic on an existing array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Allocate a matrix before filling its values<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When the shape is known but the measurements aren&#8217;t available yet, np.zeros() creates initialized storage instead of requiring a list of placeholder rows. Run this variation to allocate a float32 matrix and replace its first row.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\nmeasurements = np.zeros((2, 3), dtype=np.float32)\nmeasurements&#x5B;0] = &#x5B;1, 2, 3]\nprint(measurements)\nprint(measurements.dtype)\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The second row stays zero until you assign its measurements, and the array keeps dtype float32. Use a zero only when it has an appropriate meaning in the calculation, because an unfilled measurement and a measured zero can require different treatment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">NumPy array questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Creation choices also affect how you represent missing values or combine unlike inputs. Keep those decisions explicit before passing the array to another function.<\/p>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1790967000001\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Can a NumPy array contain different data types?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A numeric ndarray has one dtype, and construction converts its values to a common representation. An object array can reference Python objects of different types, but that doesn&#8217;t give it the behavior of a dense numeric matrix.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1790967000002\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do I create an empty NumPy array?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use np.array([]) for a length-zero array. np.empty() instead allocates an array of the requested shape without initializing its entries, so fill them before reading them as data.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1790967000003\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Are NumPy arrays mutable?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A writable NumPy array lets you assign new values to its elements. If another array shares its data, edits through either array can affect the shared values.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Python lists can hold numbers, but doing math on every element means writing a loop. A NumPy array stores numbers of one type in a grid, so you can calculate on the whole array at once. Here I&#8217;ll create arrays from Python lists with np.array(), and explain how shape and dtype describe them. What is [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":71770,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93],"tags":[],"class_list":["post-1070","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy"],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/1070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=1070"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/1070\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/71770"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=1070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=1070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}