numpy append 2d array code example

Example 1: python append to 2d array

temp_list = [[], [], [], []]
temp_list[0].append("a1")
temp_list[1].append("a2")
temp_list[2].append("a3")
temp_list[3].append("a4")

Example 2: numpy append number to array

import numpy as np
a = np.array([1, 2, 3])
newArray = np.append(a, [10, 11, 12])

Example 3: np array append

>>> import numpy as np
>>> np.append([[0, 1, 2], [3, 4, 5]],[[6, 7, 8]], axis=0)
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

Example 4: python 2d array append

arr = []
arr.append([])
arr[0].append('aa1')
arr[0].append('aa2')

Tags:

Ruby Example