If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
तो जैसा आपने पिछले topic में पढ़ा कि NumPy का use Array के साथ काम करने के लिए किया जाता है। इस topic में आप जानेंगे कि किस तरह से numPy module का use करके Array create और use करते हैं।
NumPy में array Object बनाने के लिए array method का use किया जाता जो ndarray object return करता है।
#import numpy module.
import numpy as np
arr = np.array([12,23,34,45])
#print it's type.
print('Type :', type(arr))
C:\Users\Rahulkumar\Desktop\python>python module_numpy.py Type : <class 'numpy.ndarray'>
जैसा कि आप example में देख सकते हैं , कि array method numpy module का ndarray class का object return किया है।
Note : type() function , Python का predefined function है जिसका use किसी भी variable का Data Type जानने के लिए किया जाता है।
Array create करने के लिए यह जरूरी नहीं है कि , array() method में सिर्फ list ही pass की जाए , आप list , tuple या set कोई भी array-like object pass कर सकते हैं लेकिन return हमें ndarray Object ही होगा।
For Example
#import numpy module.
import numpy as np
arr_list = np.array([12,23,34,45])
arr_tuple = np.array((12,23,34,45))
arr_set = np.array({12,23,34,45})
print('List Array Type :', type(arr_list))
print('Tuple Array Type :', type(arr_tuple))
print('Set Array Type :', type(arr_set))
C:\Users\Rahulkumar\Desktop\python>python module_numpy.py List Array Type : <class 'numpy.ndarray'>
Tuple Array Type : <class 'numpy.ndarray'>
Set Array Type : <class 'numpy.ndarray'>
अभी ऊपर जो भी आपने examples आपने देखे वो सभी one dimensional Array examples थे। आप अपनी need के according कितने ही dimension का array create कर सकते हैं।
single value को लेकर बनाया गया array 0 - dimensional कहलाता है। किसी भी array में single value अपने आप में 0 - dimensional array ही होता है।
For Example :
import numpy as np arr = np.array(90) print(arr) //Output : 90
ऐसा array जिसमे 0 - dimensional arrays as a elements हैं इसे uni-dimensional Array भी कहते हैं।-
import numpy as np
arr = np.array([12,23,3,423,2])
print(arr)
C:\Users\Rahulkumar\Desktop\python>python file.py [ 12 23 3 423 2]
ऐसा array जिसमे 1 - dimensional arrays as a elements हों , मतलब हर एक array element एक 1 - dimensional array होता है।/p>
import numpy as np
arr = np.array([ [12,23,3],[43,2,45], [2,3,4] ])
print(arr)
C:\Users\Rahulkumar\Desktop\python>python file.py [[12 23 3] [43 2 45] [ 2 3 4]]
ऐसा array जिसमे 2 - dimensional arrays as a elements हों यह सबसे rare array structure है।
import numpy as np
arr = np.array([ [[12,23,3],[43,2,45]], [[2,3,4],[23,34,23]] ])
print(arr)
C:\Users\Rahulkumar\Desktop\python>python file.py [[[12 23 3] [43 2 45]] [[ 2 3 4] [23 34 23]]]
अब आप अच्छी तरह से समझ गए होंगे कि numpy का use करके कैसे array create कर। next topic में आप पढ़ेंगे कि array elements को कैसे access करते हैं।
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook