Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 7 of 60 · python

NumPy Arrays and Data Types

Duration: 15 minutes

NumPy Arrays and Data Types

NumPy arrays (ndarray) are homogeneous – every element shares the same data type (dtype).

Creating arrays of different dims

import numpy as np

# 1‑D array (vector)
vec = np.arange(5)          # [0 1 2 3 4]

# 2‑D array (matrix)
mat = np.arange(12).reshape(3,4)
print(mat)

# 3‑D array (tensor)
# shape: (2, 3, 4)
tensor = np.arange(24).reshape(2,3,4)
print(tensor.shape)

Specifying data types

float_arr = np.array([1, 2, 3], dtype=np.float64)
int_arr = np.array([1.2, 2.5, 3.7], dtype=np.int32)  # truncates

Inspecting dtype

print(float_arr.dtype)   # float64
print(int_arr.dtype)     # int32

Common dtypes

  • np.int8, np.int16, np.int32, np.int64
  • np.uint8, np.uint16, …
  • np.float16, np.float32, np.float64
  • np.bool_

Info

Use the smallest dtype that captures your data to save memory.

Previous: Introduction to NumPyNext: Indexing, Slicing, and Iterating in NumPy