Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Array with multiple columns formatting

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading