#### EMAIL SUPPORT

dclessons@dclessons.com

AF

# Using numpy Pkg in Array

### Using numpy Pkg in Array

Posted on Jan 09, 2021

### Numpy Package

This package contains various classes, functions, variable which are used to do scientific calculation in Python. The arrays which are created by using numpy package is called as n dimensional Arrays.

In order to work with numpy, we need to import the numpy module, in to python program

Import numpy

Now in order to use any of the numpy object from this package, use format: numpy.Object.

Example:1 Write a program to create an array using numpy module.

There is another way to import everything from numpy and using this it will import everything because of *.

From numpy import *

### Uses of Numpy Packages:

We can use Numpy package to create the array using following function.

• Using array()
• Using Linspace()
• Using logspace()
• Using arrange()
• Using Zero(), Ones()

### Creating Arrays using LinSpace() Function.

This function is used to create an array, using a starting point, and ending points. The format is

Linspace(start , stop , n)

• Start: represents starting elements
• Stop: Represents ending elements

N is integer that represents number of parts of elements should be divided.

Let’s suppose: a = linspace(0 , 10, 5)

Output Array is : a = [0, 2.5, 5,7.5,10]

This range from 0 to 10 is divided to 5 equal parts.

Example2: Write a Python program to create an array using Linspace ()

### Creating Arrays using Logspace

Logspace creates evenly spaced points, in this it starts with a value which is 10 to power of start and ends to a value which is 10 to the power of stop.

Syntax: Logspace (start, stop, n)

If n is not specified, then it takes the value of 50.

Let’s understand with this example:

Logspace (1, 4, 5) then the function will starts with (10 power 1 and ends with 10 power 4). These values are then divided in to 5 equal parts.

Example 3: Write a Python program to create array using Logspace.

### Creating Arrays using Arange() Function.

This is same as range () function, the below format is used for this:

arange( start , stop, stepsize)

In this array will start from start element and will stop one element before in steps defined step size.

Arange(1 , 10, 3) , this will create array from element 1 to 9 like this : [ 1, 1+3 = 4 , 4+3 = 7] = [1,4,7].

Example 4:  Write a python program to create an array with even number up to 20.

### Comment

You are will be the first.
{"ft_lang_label":"__label__en","ft_lang_prob":0.75851417,"math_prob":0.93000174,"size":2296,"snap":"2022-27-2022-33","text_gpt3_token_len":570,"char_repetition_ratio":0.12696335,"word_repetition_ratio":0.031476997,"special_character_ratio":0.2595819,"punctuation_ratio":0.14345992,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99787724,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-04T15:48:04Z\",\"WARC-Record-ID\":\"<urn:uuid:a2057edd-eca6-43f3-9997-e1e7fc4b8314>\",\"Content-Length\":\"35900\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6345e736-4278-4a76-8c1d-939d3a5ea92d>\",\"WARC-Concurrent-To\":\"<urn:uuid:3099aa5a-c3a9-4511-a144-711be1ff8d47>\",\"WARC-IP-Address\":\"72.167.35.30\",\"WARC-Target-URI\":\"https://www.dclessons.com/using-numpy-pkg-in-array\",\"WARC-Payload-Digest\":\"sha1:BEFZEYR5P6INV4R4KNRUF6WZXVON4CEC\",\"WARC-Block-Digest\":\"sha1:LJDAYR6AKRY2MQKCUHO7QCABUB5JQO3O\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104432674.76_warc_CC-MAIN-20220704141714-20220704171714-00704.warc.gz\"}"}