How to convert NumPy array to dictionary in Python? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report See More The following article explains how to convert numpy array to dictionary in Python. Array in Numpy is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In Numpy, number of dimensions of the array is called rank of the array. A tuple of integers giving the size of the array along each dimension is known as shape of the array. An array class in Numpy is called as ndarray. Elements in Numpy arrays are accessed by using square brackets and can be initialized by using nested Python Lists. Approach To convert a numpy array to dictionary the following program uses dict(enumerate(array.flatten(), 1)) and this is what it exactly does: array.flatten: This function is used to get a copy of given array, collapsed into one dimension.enumerate: Enumerate method comes with an automatic counter/index for each of the items present in the list. The first index value will start from 0dict: this function is used to convert any object to dictionary. Example 1: Python3 # importing required libraries import numpy as np # creating a numpy array array = np.array([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]) # convert numpy array to dictionary d = dict(enumerate(array.flatten(), 1)) # print numpy array print(array) print(type(array)) # print dictionary print(d) print(type(d)) Output: [['a' 'b' 'c'] ['d' 'e' 'f'] ['g' 'h' 'i']] <class 'numpy.ndarray'> {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i'} <class 'dict'> Time Complexity: The time complexity for converting a numpy array to a dictionary is O(n), where n is the number of elements in the numpy array. Space Complexity: The space complexity for converting a numpy array to a dictionary is O(n), where n is the number of elements in the numpy array. Example 2: Python3 # importing required libraries import numpy as np # creating a numpy array array = np.array([['1', '2', '3','4','5'], ['6', '7', '8','9','10'], ['11', '12', '13','14','15']]) # convert numpy array to dictionary d = dict(enumerate(array.flatten(), 1)) # print numpy array print(array) print(type(array)) # print dictionary print(d) print(type(d)) Output: [['1' '2' '3' '4' '5'] ['6' '7' '8' '9' '10'] ['11' '12' '13' '14' '15']] <class 'numpy.ndarray'> {1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: '10', 11: '11', 12: '12', 13: '13', 14: '14', 15: '15'} <class 'dict'> Time complexity: O(n), where n is the number of elements in the numpy array. Auxiliary space: O(n), where n is the number of elements in the numpy array, due to the creation of the dictionary. Create Quiz Comment M mukulsomukesh Follow 0 Improve M mukulsomukesh Follow 0 Improve Article Tags : Python Python-Quizzes Python-numpy Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like