4.Convert a 1-D array into a 2-D array
a = np.array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'])
Answer:
Output:
array([['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i'],
['j', 'k', 'l']], dtype='<U1')
5.Add 101 to all the values in given array
a = np.arange(16).reshape(4,-1)
Answer:
Output:
array([[101, 102, 103, 104],
[105, 106, 107, 108],
[109, 110, 111, 112],
[113, 114, 115, 116]])
6.Extract the last 5 columns of this 2-D array
a = np.arange(100).reshape(5,-1)
Answer:
Output:
array([[15, 16, 17, 18, 19],
[35, 36, 37, 38, 39],
[55, 56, 57, 58, 59],
[75, 76, 77, 78, 79],
[95, 96, 97, 98, 99]])
4.
a = np.array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'])
a.reshape((4,-1))
5.
a = np.arange(16).reshape(4,-1)
a + 101
6.
a = np.arange(100).reshape(5,-1)
a[:,-5:]
Comments
Leave a comment