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

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]

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Deep Learning Project for Time Series Forecasting in Python
Deep Learning for Time Series Forecasting in Python -A Hands-On Approach to Build Deep Learning Models (MLP, CNN, LSTM, and a Hybrid Model CNN-LSTM) on Time Series Data.

MLOps Project to Build Search Relevancy Algorithm with SBERT
In this MLOps SBERT project you will learn to build and deploy an accurate and scalable search algorithm on AWS using SBERT and ANNOY to enhance search relevancy in news articles.

Ola Bike Rides Request Demand Forecast
Given big data at taxi service (ride-hailing) i.e. OLA, you will learn multi-step time series forecasting and clustering with Mini-Batch K-means Algorithm on geospatial data to predict future ride requests for a particular region at a given time.

Build ARCH and GARCH Models in Time Series using Python
In this Project we will build an ARCH and a GARCH model using Python

NLP Project on LDA Topic Modelling Python using RACE Dataset
Use the RACE dataset to extract a dominant topic from each document and perform LDA topic modeling in python.

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

Hands-On Approach to Master PyTorch Tensors with Examples
In this deep learning project, you will learn how to perform various operations on the building block of PyTorch : Tensors.

ML Model Deployment on AWS for Customer Churn Prediction
MLOps Project-Deploy Machine Learning Model to Production Python on AWS for Customer Churn Prediction

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Many-to-One LSTM for Sentiment Analysis and Text Generation
In this LSTM Project , you will build develop a sentiment detection model using many-to-one LSTMs for accurate prediction of sentiment labels in airline text reviews. Additionally, we will also train many-to-one LSTMs on 'Alice's Adventures in Wonderland' to generate contextually relevant text.