numpy adds elements to an empty 2 D array

  • 2021-01-18 06:34:56
  • OfStack

It goes straight to the code


x = np.empty(shape=[0, 4], int)
x = np.append(x, [[1,2,3,4]], axis = 0)
x = np.append(x, [[1,2,3,4]], axis = 0)

This adds two rows and four columns of data. Note that there are two levels of parentheses in append. This is very important. If you miss this, it will not be a 2-dimensional array, and if you use axis you will report a dimension mismatch.


Related articles: