Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello,

I do not know, if this construction is useful, but you could do the following:

 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,
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 = array([[1 2], [1 2 3], [3 2 2 3]], dtype=object)

Hello,

I do not know, if this construction is useful, but you could do the following:

 L1=np.array([1,2])                         
 L2=np.array([1,2,3])
 L3=np.array([3,2,2,3])
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], = 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,
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