How to use NumPy In Python

Numpy is used to process the arrays, we can get the values by using key or index

Python3




# import numpy module
import numpy as np
 
# create numpy data
data = np.array([(10, 20), (50, 60)],
                dtype=[('value1', int),
                       ('value2', int)])
 
# display by using index
print(data[0])
 
# display by using key
print(data['value1'])


Output:

(10, 20)
[10 50]

Time Complexity: O(n)
Auxiliary Space: O(n)



Python – Convert list of dictionaries to dictionary of lists

In this article, we will discuss how to convert a list of dictionaries to a dictionary of lists.

Similar Reads

Method 1: Using for loop

By iterating based on the first key we can convert list of dict to dict of list. Python program to create student list of dictionaries...

Method 2: Using dictionary comprehension

...

Method 3: Using pandas DataFrame

...

Method 4: Using NumPy

Here we are using a dictionary comprehension to convert a list of dictionaries into the dictionary of the list, so we are passing the list as values based on keys in the new dictionary...

Contact Us