I have multiple arrays and I would like to combine them together so when I call a row, the 1st value of each array is shown. How can I do this?
array1 = ['happy','sad','tired']
array2 = ['oranges', 'apples', 'grapes']
array3 = ['monkeys','elephants','tigers']
array = [array1,array2,array3]
output:['happy','sad','tired'],['oranges','apples','grapes']etc...
wanted output: ['happy','oranges','monkeys'],['sad','apples','elephants']etc...
>Solution :
Is there a reason you don’t want to use numpy? That would make things very simple.
import numpy as np
array1 = ['happy','sad','tired']
array2 = ['oranges', 'apples', 'grapes']
array3 = ['monkeys','elephants','tigers']
array = np.array([array1,array2,array3]).reshape(3, -1)
Then you can access either rows or columns with indexing:
# column
array[:, 0]
# Out[224]: array(['happy', 'oranges', 'monkeys'], dtype='<U9')
# row
array[0, :]
# Out[224]: array(['happy', 'sad', 'tired'], dtype='<U9')