<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to get an array from the results of an iteration in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-get-an-array-from-the-results-of-an/m-p/1075816#M61577</link>
    <description>&lt;P&gt;Thank you Dan!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jul 2021 12:52:05 GMT</pubDate>
    <dc:creator>mlopezr95984</dc:creator>
    <dc:date>2021-07-06T12:52:05Z</dc:date>
    <item>
      <title>How to get an array from the results of an iteration</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-an-array-from-the-results-of-an/m-p/1075758#M61572</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Hello, &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I am trying to generate an array out of the results of this iteration.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#3366FF"&gt;import numpy as np&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#3366FF"&gt;num=3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#3366FF"&gt;for x in range(num+1):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#3366FF"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; a=np.array([2,x])&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#3366FF"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; print(a)&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#FF0000"&gt;Result:&lt;/FONT&gt;&lt;BR /&gt;[2 0]
[2 1]
[2 2]
[2 3]&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#000000"&gt;So, I would like to have an array&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#000000"&gt;a = [2 0 2 1 2 2 2 3]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#000000"&gt;I have not figured out how to apply a np.concatenate as it does not allow me to assign a variable to each&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#000000"&gt;&amp;nbsp;result.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#000000"&gt;Any ideas?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#000000"&gt;Thank you!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 04:58:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-an-array-from-the-results-of-an/m-p/1075758#M61572</guid>
      <dc:creator>mlopezr95984</dc:creator>
      <dc:date>2021-07-06T04:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to get an array from the results of an iteration</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-an-array-from-the-results-of-an/m-p/1075767#M61573</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;num=3
lst =[]
for x in range(num+1):
      lst.append([2, x])
out = np.array(lst)
out
Out[4]: 
array([[2, 0],
       [2, 1],
       [2, 2],
       [2, 3]])
out.ravel()
Out[5]: array([2, 0, 2, 1, 2, 2, 2, 3])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;better&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;num=3
lst =[]
for x in range(num+1):
      lst.extend([2, x])
out = np.array(lst)
out
Out[7]: array([2, 0, 2, 1, 2, 2, 2, 3])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;better&lt;/P&gt;&lt;P&gt;skip iteration all together&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;num = 4
val = 2
a = np.empty(shape=(num, 2), dtype=np.int32)
a.fill(val)
a[:, 1] = np.arange(num)
a
array([[2, 0],
       [2, 1],
       [2, 2],
       [2, 3]])
a.ravel()
array([2, 0, 2, 1, 2, 2, 2, 3])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are more efficient ways.&lt;/P&gt;&lt;P&gt;Also note, create the final array at the end&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 08:02:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-an-array-from-the-results-of-an/m-p/1075767#M61573</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-07-06T08:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get an array from the results of an iteration</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-an-array-from-the-results-of-an/m-p/1075816#M61577</link>
      <description>&lt;P&gt;Thank you Dan!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 12:52:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-an-array-from-the-results-of-an/m-p/1075816#M61577</guid>
      <dc:creator>mlopezr95984</dc:creator>
      <dc:date>2021-07-06T12:52:05Z</dc:date>
    </item>
  </channel>
</rss>

