How to create a numpy array sequence given only the starting point and length and the step?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to create a numpy array sequence given only the starting point and length and the step?

How to create a numpy array sequence given only the starting point and length and the step?

This recipe helps you create a numpy array sequence given only the starting point and length and the step

0

Recipe Objective

How to create a numpy array sequence given only the starting point, length and the step? This is done byb using the "arange" function available in the Numpy library. The "arange" function is like: arange(start, stop, step, dtype)

Start - by default it is "0", it is the start of the interval range.

Stop - It is the end of the interval range.

step - By default it is "1", it is nothing but the step size of the interval

dtype - data type of the output array

Step 1 - Import library

import numpy as np

Step 2 - Final Result

print("This is arange with reshape function:","\n", np.arange(6).reshape(2,3), "\n") print("This is arange function with start and stop:","\n", np.arange(6, 12), "\n") print("This is arange function with start, stop and step","\n", np.arange(1, 10, 2))
This is arange with reshape function: 
 [[0 1 2]
 [3 4 5]] 

This is arange function with start and stop: 
 [ 6  7  8  9 10 11] 

This is arange function with start, stop and step 
 [1 3 5 7 9]

Relevant Projects

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.