Numpy Array Creations:

Using list for array creation – To store multiple values in single variable we use arrays. In Python, we do not have built-in functions supporting arrays, but we can use lists instead for Data Science.

Example:

Numpy Array Creations in Python for Data Science - PST Analytics

Array functions for array creation:

Array (data type, list) is the function which we use for the creation of arrays with data types and value lists specified in the arguments.

Example:

Numpy methods for array creation:

In Numpy we can find several functions for creation of arrays with initial place holders. Example: np.zeroes, np.empty, etc.

numpy.empty(shape, dtype = float, order = ‘C’): It will return a new array of specific shape and type with random values.

Numpy Array Creations in Python for Data Science - PST Analytics

numpy.zeroes(shape, dtype = None, order = ‘C’): It will return a new array of specific shape and type with zeroes.

Numpy Array Creations in Python for Data Science - PST Analytics

Reshping array:

The method reshape is there for reshaping an array. So, any array can be reshape and convert to another array provided the original size of array remains same.

numpy.reshape(array, shape, order = ‘C’): It is there for shaping an array without changing the data of array.

For creation of sequrnce of numbers Numoy has a function analogous to range which returns arrays instead of lists.

arrange will return evenly spaced values within given interval. The step size is specific.

linespace will return evenly spaced values within given interval. Num number is returned.

Arrange([start], stop[, step,][, dtype): It will return an array with evenly spaced elements according to the given interval. So, the mentioned interval is half opened in python for data science.

numpy.linespace(start, stop, num = 50, endpoint = True, retstep = False, dtype = None): It will return number spaces evenly distributed according to the interval. This is similar to arrange but it uses sample number and not step.

Flatten array: The flatten method is there for getting a copy of array collapsed in one dimension. So, it will accept order argument. Its default value is ‘C’.

Numpy.ndarray.flatten(order = ‘C’): It will retrn a copy of array collapsed into one dimension.

Methods of array creation:

Numpy Array Creations in Python for Data Science - PST Analytics

So, to learn more about it in python for data sciecne, you can check this and this as well.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.