NumPy

Python परिचय

Hugo Bowne-Anderson

Data Scientist at DataCamp

लिस्ट्स रिकैप

  • शक्तिशाली

  • मानों का कलेक्शन

  • अलग-अलग प्रकार रख सकता है

  • बदलें, जोड़ें, हटाएँ

  • डेटा साइंस के लिए ज़रूरी

    • कलेक्शन पर गणितीय ऑपरेशन

    • स्पीड

Python परिचय

चित्रण

height = [1.73, 1.68, 1.71, 1.89, 1.79]
height
[1.73, 1.68, 1.71, 1.89, 1.79]
weight = [65.4, 59.2, 63.6, 88.4, 68.7]
weight
[65.4, 59.2, 63.6, 88.4, 68.7]
weight / height ** 2
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
Python परिचय

समाधान: NumPy

  • न्यूमेरिक Python

  • Python List का विकल्प: NumPy Array

  • पूरे arrays पर कैलकुलेशन

  • आसान और तेज़

  • इंस्टॉलेशन

    • टर्मिनल में: pip3 install numpy
Python परिचय

NumPy

import numpy as np

np_height = np.array(height) np_height
array([1.73, 1.68, 1.71, 1.89, 1.79])
np_weight = np.array(weight)
np_weight
array([65.4, 59.2, 63.6, 88.4, 68.7])
bmi = np_weight / np_height ** 2
bmi
array([21.85171573, 20.97505669, 21.75028214, 24.7473475 , 21.44127836])
Python परिचय

तुलना

height = [1.73, 1.68, 1.71, 1.89, 1.79]
weight = [65.4, 59.2, 63.6, 88.4, 68.7]
weight / height ** 2
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
np_height = np.array(height)
np_weight = np.array(weight)
np_weight / np_height ** 2
array([21.85171573, 20.97505669, 21.75028214, 24.7473475 , 21.44127836])
Python परिचय

NumPy: टिप्पणियाँ

np.array([1.0, "is", True])
array(['1.0', 'is', 'True'], dtype='<U32')
  • NumPy arrays: केवल एक ही प्रकार रखते हैं
Python परिचय

NumPy: टिप्पणियाँ

python_list = [1, 2, 3]
numpy_array = np.array([1, 2, 3])
python_list + python_list
[1, 2, 3, 1, 2, 3]
numpy_array + numpy_array
array([2, 4, 6])
  • अलग प्रकार: अलग व्यवहार!
Python परिचय

NumPy सबसेटिंग

bmi
array([21.85171573, 20.97505669, 21.75028214, 24.7473475 , 21.44127836])
bmi[1]
20.975
bmi > 23
array([False, False, False,  True, False])
bmi[bmi > 23]
array([24.7473475])
Python परिचय

अभ्यास करते हैं!

Python परिचय

Preparing Video For Download...