w3resource
ankara escort
malatya escort
NumPy Exercises

NumPy: Create a 2-dimensional array of size 2 x 3

NumPy: Array Object Exercise-37 with Solution

Write a NumPy program to create a 2-dimensional array of size 2 x 3 (composed of 4-byte integer elements), also print the shape, type and data type of the array.

Pictorial Presentation:

Python NumPy: Create a  2-dimensional array of size 2 x 3

Sample Solution:-

NumPy Code:

import numpy as np
x = np.array([[2, 4, 6], [6, 8, 10]], np.int32)
print(type(x))	
print(x.shape)
print(x.dtype)

Sample Output:

<class 'numpy.ndarray'>                                                
(2, 3)                                                                 
int32 

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to create a contiguous flattened array.
Next: Write a NumPy program to create a new shape to an array without changing its data.

What is the difficulty level of this exercise?



New Exercises:R Programming