Data Adding to Array


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

Appending using axis

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
Subscribe to our YouTube Channel here

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer