Examples for Array Manipulation



In [1]:
#'' and "" work the same way
a = 'red'
b = "blue"
c = [a,b,'green',"magenta"]
print(c)


['red', 'blue', 'green', 'magenta']

In [2]:
print(c[0])
print(c[1:3])


red
['blue', 'green']

In [3]:
d=['redish','bluish']+['greenish']
print(d)


['redish', 'bluish', 'greenish']

In [4]:
e = ['red']*5
print(e)
e = e + ['blue']
print(e)


['red', 'red', 'red', 'red', 'red']
['red', 'red', 'red', 'red', 'red', 'blue']

In [5]:
f = ['red','blue',None]*2
print(f)


['red', 'blue', None, 'red', 'blue', None]

In [6]:
import numpy as np
np.column_stack(([1, 2, 3], [4, 5, 6]))
np.column_stack((e,f))


Out[6]:
array([['red', 'red'],
       ['red', 'blue'],
       ['red', None],
       ['red', 'red'],
       ['red', 'blue'],
       ['blue', None]], dtype=object)