Python में defined data types के अलावा numpy में कुछ additional data types भी हैं , जिन्हे array define करते समय define करना पड़ता है।

What is data type?

Data Type का simply मतलब है किसी variable का type, जिससे हमें पता चल सके कि कोई variable किस type की value hold किये हुए है , या in future किस type की value hold करेगा।

Python में built in Data Types कुछ प्रकार हैं -

Python Data Types
Text : str
Numeric : int, float, complex
Sequence : list, tuple, range
Binary : bytes, bytearray, memoryview
Mapping : dict
Set : set, frozenset
Boolean : bool

ये तो वो data types थे जिन्हे python support करती है , अब नीचे कुछ data types की list है जिन्हे numpy module support करता है।

  1. i - integer
  2. b - boolean
  3. f - float
  4. c - complex float
  5. m - timedelta
  6. M - datetime
  7. O - object
  8. S - string
  9. U - unicode string

dtype

data type को set या check करने के लिए , ndarray की एक property dtype होती है , जिससे हमें पता चलता है कि जो array create किया गया है , वो किस type के elements को होल्ड किये हुए है।

Example
Copy Fullscreen Close Fullscreen Run
#import numpy module.
import numpy as np
#make an array as int type.
arr = np.array([12,12,23,3,445,45, 32])
print(arr.dtype)

#define array with data type.
arr = np.array(["name", "name2", "name3", "other name"], dtype='S')
print(arr.dtype)
Output
C:\Users\Rahulkumar\Desktop\python>python module_numpy.py
int64
|S10

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers