ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 01 Aug 2013 16:36:01 +0200Add Numpy array into other Numpy arrayhttps://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/Hi experts!!
My code starts with a empty array (POPOPO=np.array([])).
In the next lines, np.array are created (L1, L2, ...). How can it add this new-created-arrays into POPOPO in order to obtain the array POPOPO= [[L1],[L2],...]?
Its important to note that L1, L2,.... have different lenght.
Waiting for your answers.
Thanks in advance!Sat, 27 Jul 2013 11:21:42 +0200https://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/Comment by jack77 for <p>Hi experts!!</p>
<p>My code starts with a empty array (POPOPO=np.array([])).</p>
<p>In the next lines, np.array are created (L1, L2, ...). How can it add this new-created-arrays into POPOPO in order to obtain the array POPOPO= [[L1],[L2],...]?
Its important to note that L1, L2,.... have different lenght.</p>
<p>Waiting for your answers.</p>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/?comment=17231#post-id-17231Hello mresimulator, what type of arrays are the L1, L2,.. are they one-dimensional?
btw, did you solve the problem already?Sat, 27 Jul 2013 20:19:27 +0200https://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/?comment=17231#post-id-17231Comment by jack77 for <p>Hi experts!!</p>
<p>My code starts with a empty array (POPOPO=np.array([])).</p>
<p>In the next lines, np.array are created (L1, L2, ...). How can it add this new-created-arrays into POPOPO in order to obtain the array POPOPO= [[L1],[L2],...]?
Its important to note that L1, L2,.... have different lenght.</p>
<p>Waiting for your answers.</p>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/?comment=17229#post-id-17229what did you tried so far to fill the POPOPO array?Sat, 27 Jul 2013 21:01:04 +0200https://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/?comment=17229#post-id-17229Answer by jack77 for <p>Hi experts!!</p>
<p>My code starts with a empty array (POPOPO=np.array([])).</p>
<p>In the next lines, np.array are created (L1, L2, ...). How can it add this new-created-arrays into POPOPO in order to obtain the array POPOPO= [[L1],[L2],...]?
Its important to note that L1, L2,.... have different lenght.</p>
<p>Waiting for your answers.</p>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/?answer=15300#post-id-15300Hello,
<br><br>
I do not know, if this construction is useful, but you could do the following:
import numpy as np
L1 = np.array( [1,2] )
L2 = np.array( [1,2,3] )
L3 = np.array( [3,2,2,3] )
L = np.array( [L1, L2, L3], dtype=object )
L[0] # will return array([1, 2])
if the number of the basic arrays are not known or is variable, <br>
you could compose a command string and then use
count = 3
cmdstr = "L = np.array(["
for i in range(1, count): cmdstr = cmdstr+ 'L'+str(i)+','
cmdstr = cmdstr+ 'L'+str(count)
cmdstr = cmdstr+"], dtype=object)"
cmdstr # : 'L = np.array([L1,L2,L3], dtype=object)'
exec(cmdstr) # L will be = array([[1 2], [1 2 3], [3 2 2 3]], dtype=object)
Remark: it did'nt work neither with *np.concatenate* nor with *np.append*Thu, 01 Aug 2013 16:36:01 +0200https://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/?answer=15300#post-id-15300