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

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

NLP Project to Build a Resume Parser in Python using Spacy
Use the popular Spacy NLP python library for OCR and text classification to build a Resume Parser in Python.

Langchain Project for Customer Support App in Python
In this LLM Project, you will learn how to enhance customer support interactions through Large Language Models (LLMs), enabling intelligent, context-aware responses. This Langchain project aims to seamlessly integrate LLM technology with databases, PDF knowledge bases, and audio processing agents to create a comprehensive customer support application.

Time Series Python Project using Greykite and Neural Prophet
In this time series project, you will forecast Walmart sales over time using the powerful, fast, and flexible time series forecasting library Greykite that helps automate time series problems.

Data Analysis of Working Capital Management using Tableau
In this Data Analysis Project using Tableau, you will focus on optimizing working capital by analyzing receivables and payables data using Tableau and build actionable dashboards.

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .

PyTorch Project to Build a LSTM Text Classification Model
In this PyTorch Project you will learn how to build an LSTM Text Classification model for Classifying the Reviews of an App .

OSZAR »