EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials NumPy Tutorial NumPy Data Types
Secondary Sidebar
NumPy Tutorial
  • Basics
    • Introduction to NumPy
    • Install NumPy
    • NumPy Data Types
    • NumPy Functions
    • NumPy Histogram
    • numPy.where()
    • numpy.sort
    • NumPy floor()
    • Matrix in NumPy
    • NumPy Matrix Transpose
    • Matrix Multiplication in NumPy
    • NumPy Arrays
    • NumPy Array Functions
    • NumPy Ndarray
    • NumPy Array Append
    • NumPy?empty array
    • NumPy ndarray tolist
    • numpy.linspace()
    • NumPy.argmax()
    • NumPy Linear Algebra
    • numpy.diff()
    • numpy.unique( )
    • NumPy zeros
    • numpy.mean()
    • numpy.dot()
    • Numpy.argsort()
    • numpy.pad()
    • numpy.ravel()
    • NumPy stack
    • NumPy?vstack
    • NumPy hstack
    • NumPy sum
    • NumPy cumsum
    • NumPy max
    • NumPy squeeze
    • NumPy median
    • NumPy Round
    • NumPy NaN
    • NumPy divide
    • NumPy square
    • NumPy ones
    • NumPy?Meshgrid
    • NumPy exponential
    • NumPy percentile
    • NumPy fft
    • NumPy flatten
    • NumPy Concatenate
    • NumPy Outer
    • NumPy zip
    • NumPy Newaxis
    • NumPy Format
    • Numpy Eigenvalues
    • Numpy Random Seed ()
    • NumPy random choice
    • NumPy random normal
    • NumPy unravel_index
    • Numpy.eye()
    • NumPy append
    • NumPy searchsorted
    • NumPy shape
    • NumPy reshape
    • NumPy savetxt
    • NumPy genfromtxt
    • NumPy standard deviation
    • NumPy covariance
    • NumPy repeat
    • NumPy?Tile
    • NumPy Broadcasting
    • NumPy axis
    • NumPy correlation
    • NumPy logspace()
    • NumPy Normal Distribution
    • NumPy Convolve
    • NumPy Indexing
    • NumPy norm
    • NumPy Inverse
    • NumPy linalg norm
    • NumPy nonzero
    • NumPy polyfit
    • NumPy?2D array
    • NumPy concatenate arrays
    • NumPy 3D array
    • NumPy Array Indexing
    • NumPy datetime64
    • NumPy Identity Matrix
    • NumPy for loop
    • NumPy Factorial
    • NumPy isclose
    • NumPy find
    • NumPy Vector
    • NumPy linear regression
    • NumPy interpolate
    • NumPy datetime
    • Numpy.clip()
    • Numpy.loadtxt()
    • NumPy Cross Product
    • NumPy arange
    • Numpy.save()
    • NumPy Empty
    • NumPy Log
    • NumPy random
    • NumPy size
    • NumPy load
    • NumPy map
    • NumPy power
    • NumPy? Vectorize
    • NumPy? zeros_like
    • NumPy.array() in Python

Related Courses

Pandas And NumPy Training Course

Python Training Course

Software Development Course Training

NumPy Data Types

By Priya PedamkarPriya Pedamkar

NumPy-Data-Types

Introduction to NumPy Data Types

The data types are used for defining a variable with a specific type that is used for identifying the variable and allowing the given types of data. Numpy is a data type used on Python programming, and comes along with the python package that can be used for multiple scientific computational operations. A few of the commonly used NumPy data types are np.byte, np.short, np.int_, np.uintc, np.ubyte, np.bool_, np.longlong, np.single, np.half, np.single, np.double, np.csingle, np.int8, np.int64, np.int32, np.intp, np.unitp, np.float64, etc.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,768 ratings)

Numpy Data Types

The various data types supported by numpy are :

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Numpy data type Closely associated C data type Storage Size Description
np.bool_ bool 1 byte can hold boolean values, like (True or False) or (0 or 1)
np.byte signed char 1 byte can hold values from 0 to 255
np.ubyte unsigned char 1 byte can hold values from -128 to 127
np.short signed short 2 bytes can hold values from -32,768 to 32,767
np.ushort unsigned short 2 bytes can hold values from 0 to 65,535
np.uintc unsigned int 2 or 4 bytes can hold values from 0 to 65,535 or 0 to 4,294,967,295
np.int_ long 8 bytes can hold values from -9223372036854775808 to 9223372036854775807
np.uint unsigned long 8 bytes 0 to 18446744073709551615
np.longlong long long 8 bytes can hold values from -9223372036854775808 to 9223372036854775807
np.ulonglong unsigned long long 8 bytes 0 to 18446744073709551615
np.half / np.float16 — allows half float precision with
Format: sign bit, 5 bits exponent, 10 bits mantissa
np.single float 4 bytes allows single float precision
Format: sign bit, 8 bits exponent, 23 bits mantissa
np.double double 8 bytes allows double float precision
Format: sign bit, 11 bits exponent, 52 bits mantissa.
np.longdouble long double 8 bytes extension of float
np.csingle float complex 8 bytes can hold complex with real and imaginary parts up to
single-precision float
np.cdouble double complex 16 bytes can hold complex with real and imaginary parts up to
double-precision float
np.clongdouble long double complex 16 bytes extension of float for complex number
np.int8 int8_t 1 byte can hold values from -128 to 127
np.int16 int16_t 2 bytes can hold values from -32,768 to 32,767
np.int32 int32_t 4 bytes can hold values from -2,147,483,648 to 2,147,483,647
np.int64 int64_t 8 bytes can hold values from -9223372036854775808 to 9223372036854775807
np.uint8 uint8_t 1 byte can hold values from 0 to 255
np.uint16 uint16_t 2 bytes can hold values from 0 to 65,535
np.uint32 uint32_t 4 bytes can hold values from 0 to 4,294,967,295
np.uint64 uint64_t 8 bytes can hold values from 0 to 18446744073709551615
np.intp intptr_t 4 bytes a signed integer used for indexing
np.uintp uintptr_t 4 bytes an unsigned integer used for holding a pointer
np.float32 float 4 bytes single float precision
np.float64 double 8 bytes double float precision
np.complex64 float complex 8 bytes single float precision in complex numbers
np.complex128 double complex 16 bytes double float precision in complex numbers

Examples of NumPy Data Types

Now, let’s understand how a particular numpy data type is used.

Example #1

Creating a data type object

dt = np.dtype(np.int8)

Output:

NumPy Data Types 1

Example #2

Finding the size of a data type

dt = np.dtype(np.int8)
name = dt.name
sizeoftype = dt.itemsize
print('name:',name, 'size:',sizeoftype)

Output:

NumPy Data Types 2

Example #3

Creating a data type object using unique symbols for each data type

Each data type in numpy has an associated character code that uniquely identifies it.

dt = np.dtype('i4')

Output:

NumPy Data Types 3

Example #4

Using data types to create a structured array

employee_info = np.dtype([('name','S10'), ('age', 'i1'),('salary', 'f4'),('rating', 'f4')])
print(employee_info)

Output:

Example 4

a = np.array([('Karthik',31,20000,3.84),('Rita',25,25123.34,4.41)], dtype = employee_info)
print (a)

Output:

Example 5

Conclusion

Numpy data types are more or less like the C data types. They can be roughly categorized into a bool, byte, int, float, double and complex. It is a must for good programmers to understand how data is stored and manipulated. This can be achieved by understanding data types effectively.

Recommended Articles

This is a guide to NumPy Data Types. Here we discuss How a particular numpy data type is used along with the Examples. You may also have a look at the following articles to learn more –

  1. What is NumPy?
  2. Learn the Examples of NumPy Histogram
  3. NumPy floor() Function with Example
  4. Guide to NumPy Ndarray
  5. Matrix in NumPy | Examples | How to Create?
Popular Course in this category
Pandas and NumPy Tutorial (4 Courses, 5 Projects)
  4 Online Courses |  5 Hands-on Projects |  37+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Python Certifications Training Program (40 Courses, 13+ Projects)4.9
All in One Software Development Bundle (600+ Courses, 50+ projects)4.8
1 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more