Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
Lua Data Types
Next article icon

Numpy data Types

Last Updated : 23 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

NumPy is a powerful Python library that can manage different types of data. Here we will explore the Datatypes in NumPy and How we can check and create datatypes of the NumPy array.

DataTypes in NumPy

A data type in NumPy is used to specify the type of data stored in a variable. Here is the list of characters available in NumPy to represent data types.

Character

Meaning

b

Boolean

f

Float

m

Time Delta

O

Object

U

Unicode String

i

Integer

u

Unsigned Integer

c

Complex Float

M

DateTime

S

String

V

A fixed chunk of memory for other types (void)

The list of various types of data types provided by NumPy are given below:

Data Type

Description

bool_

Boolean

int_

Default integer type (int64 or int32)

intc

Identical to the integer in C (int32 or int64)

intp

Integer value used for indexing

int8

8-bit integer value (-128 to 127)

int16

16-bit integer value (-32768 to 32767)

int32

32-bit integer value (-2147483648 to 2147483647)

int64

64-bit integer value (-9223372036854775808 to 9223372036854775807)

uint8

Unsigned 8-bit integer value (0 to 255)

uint16

Unsigned 16-bit integer value (0 to 65535)

uint32

Unsigned 32-bit integer value (0 to 4294967295)

uint64

Unsigned 64-bit integer value (0 to 18446744073709551615)

float_

Float values

float16

Half precision float values

float32

Single-precision float values

float64

Double-precision float values

complex_

Complex values

complex64

Represent two 32-bit float complex values (real and imaginary)

complex128

Represent two 64-bit float complex values (real and imaginary)

Checking the Data Type of NumPy Array

We can check the datatype of Numpy array by using dtype. Then it returns the data type all the elements in the array.

Python
import numpy as np  # Create a NumPy array arr = np.array([1, 2, 3, 4, 5])  # Check the data type of the array data_type = arr.dtype print(data_type) 

Output
int64 

Create Arrays With a Defined Data Type

We can create an array with a defined data type by specifying "dtype" attribute in numpy.array() method while initializing an array.

Python
import numpy as np  arr1 = np.array([1, 2, 3, 4], dtype=np.float64)    # Creating a 3x3 int32 array of zeros arr2 = np.zeros((3, 3), dtype=np.int32)    # Creating a 2x2 complex128 array of ones arr3 = np.ones((2, 2), dtype=np.complex128)    # Creating a 1D bool array arr4 = np.empty((4,), dtype=np.bool_)    # Print the arrays and their data types print(arr1.dtype) print(arr2.dtype) print(arr3.dtype) print(arr4.dtype) 

Output
float64 int32 complex128 bool 

Convert Data Type of NumPy Arrays

We can convert data type of an arrays from one type to another using astype() function.

Python
import numpy as np  arr1 = np.array([1.2, 2.5, 3.7])  # Converting to int32 arr2 = arr1.astype(np.int32)    # Print new array and its type print(arr2) print(arr2.dtype) 

Output
[1 2 3] int32 

Next Article
Lua Data Types
author
sagar99
Improve
Article Tags :
  • Python
  • Numpy
  • Python-numpy
Practice Tags :
  • python

Similar Reads

  • Lua Data Types
    In Lua, data types define the kind of values a variable can hold. Since Lua is a dynamically typed language, variables can change their types during execution, which provides flexibility but requires careful management. What are Data Types in Lua Programming Language?In Lua, variables don't have fix
    6 min read
  • Python Data Types
    Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
    10 min read
  • R Data Types
    R Data types are used to specify the kind of data that can be stored in a variable. For effective memory consumption and computation, the right data type must be selected. Each R data type has its own set of regulations and restrictions. Variables are not needed to be declare with a data type in R,
    7 min read
  • Check data type in NumPy
    Numpy, is originally called numerical python, but in short, we pronounce it as Numpy. NumPy is a general-purpose array-processing package in Python. It provides high-performance multidimensional data structures like array objects and tools for working with these arrays. Numpy provides faster and mor
    5 min read
  • C++ Numeric Data Type
    There are mainly 3 types of Numeric Data Types in C++ int unsigned intshort intunsigned short int long intunsigned long intlong long intunsigned long long intfloat double long double1. Integer (int) An integer is a type of datatype that can store integer values. Integer acquires 4 bytes in memory an
    4 min read
  • DynamoDB - Data Types
    DynamoDB supports many different data types for attributes within a table. They can be categorized as follows: Scalar Types – A scalar type can represent exactly one value. The scalar types are number, string, binary, Boolean, and null.Document Types – A document type can represent a complex structu
    6 min read
  • PL/ SQL Data Types
    PL/SQL (Procedural Language/Structured Query Language) is a procedural extension language for SQL used specifically for the Oracle database to ease the management of data and the flow of operations. A core feature of PL/SQL is its diverse set of data types, designed to handle everything from simple
    6 min read
  • MATLAB - Data Types
    MATLAB is a platform which provides millions of Engineers and Scientists to analyze data using programming and numerical computing algorithm and also help in creating models. Data types are particular types of data items defined by the values they can store in them, generally, in programming languag
    5 min read
  • Kotlin Data Types
    The most fundamental data type in Kotlin is the Primitive data type and all others are reference types like array and string. Java needs to use wrappers (java.lang.Integer) for primitive data types to behave like objects but Kotlin already has all data types as objects. There are different data type
    3 min read
  • MariaDB Data Types
    MariaDB is an open-source software It has implemented various performance improvements over MySQL. It includes various enhancements such as the Aria storage engine, the Thread Pool feature, and the MaxScale proxy, all of which provide better performance and scalability. MariaDB has a large number of
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences