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

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

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

Build a Graph Based Recommendation System in Python -Part 1
Python Recommender Systems Project - Learn to build a graph based recommendation system in eCommerce to recommend products.

CycleGAN Implementation for Image-To-Image Translation
In this GAN Deep Learning Project, you will learn how to build an image to image translation model in PyTorch with Cycle GAN.

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

MLOps using Azure Devops to Deploy a Classification Model
In this MLOps Azure project, you will learn how to deploy a classification machine learning model to predict the customer's license status on Azure through scalable CI/CD ML pipelines.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

AWS MLOps Project for Gaussian Process Time Series Modeling
MLOps Project to Build and Deploy a Gaussian Process Time Series Model in Python on AWS

Azure Text Analytics for Medical Search Engine Deployment
Microsoft Azure Project - Use Azure text analytics cognitive service to deploy a machine learning model into Azure Databricks

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.