EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials NumPy Tutorial NumPy Data Types
 

NumPy Data Types

Priya Pedamkar
Article byPriya Pedamkar

Updated March 23, 2023

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.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Numpy Data Types

The various data types supported by numpy are :

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?

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA

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

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

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

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

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

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW