How to Create NumPy Array

Creating NumPy Array

  • Creating a NumPy array is quite easy. You just have to import numpy library and there, you are good to go.
  • Numpy array object is known as ndarray.
  • We can create this object with either arange() or array() function.
  • In the code below np is the alias name that I have given for numpy. Now, I don’t have to write numpy every time instead I can use np. 

  • We can also use lists, set or any array-like object with array() function to create numpy array

Some common attributes of numpy array

  • dtype :Data type object returns data type of  items in array

  • ndim : Returns the number of dimension of an array

  • shape : Returns tuples consisting  shape of an array

  • size : Returns the size of an array

  • itemsize : Returns number of bytes required for storing each element in an array

 

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories