import numpy as np
npr=np.array([[0,1,2,4],[3,4,5,6],[6,7,8,9]]) #
print(npr.ndim) # 2
print(npr.shape) # (3,4)
print(npr)
npr1=np.append(npr,[[10,11,12,13]],axis=0)
print(npr1)
Output
2
(3, 4)
[[0 1 2 4]
[3 4 5 6]
[6 7 8 9]]
[[ 0 1 2 4]
[ 3 4 5 6]
[ 6 7 8 9]
[10 11 12 13]]
ValueError: all the input arrays must have same number of dimensions
import numpy as np
npr=np.array([[0,1,2,4],[3,4,5,6],[6,7,8,9]])
npr1=np.array([[10,11,12,13],[21,22,23,24],[31,32,34,35]])
npr2=np.append(npr,npr1,axis=0)
print(npr2)
Output
[[ 0 1 2 4]
[ 3 4 5 6]
[ 6 7 8 9]
[10 11 12 13]
[21 22 23 24]
[31 32 34 35]]
Change the Axis to 1
npr2=np.append(npr,npr1,axis=1)
Output
[[ 0 1 2 4 10 11 12 13]
[ 3 4 5 6 21 22 23 24]
[ 6 7 8 9 31 32 34 35]]
Numpy
random.randint , Random Integers
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.