{"id":12794,"date":"2023-04-13T13:41:17","date_gmt":"2023-04-13T08:11:17","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=12794"},"modified":"2025-10-10T07:55:38","modified_gmt":"2025-10-10T11:55:38","slug":"numpy","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/numpy\/","title":{"rendered":"NumPy"},"content":{"rendered":"\n<p>NumPy is a python package. It will stand for Numerical Python. This is considered as a library consisting of multidimensional array objects and also a collection of routines for managing arrays.<\/p>\n\n\n\n<p>The ancestor of <a href=\"https:\/\/en.wikipedia.org\/wiki\/NumPy\" rel=\"nofollow noopener\" target=\"_blank\">Numpy<\/a> was developed by Jim Hugunin. There are other packages Numarray also developed that have some additional functionalities.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Operations using Numpy:<\/h2>\n\n\n\n<p>By using a developer who may perform the operations are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Mathematical and logical operations on arrays<\/li>\n\n\n\n<li>Fourier transforms and routines for the shape manipulations<\/li>\n\n\n\n<li>These operations are linked to linear algebra. NumPy has default built-in functions for linear algebra and random number generation.<\/li>\n<\/ul>\n\n\n\n<p>NumPy will be used with a scipy (scientific python) and mat-potlib. This is a combination that will be widely used as a replacement for Matlab, a popular platform for any technical computing. The <a href=\"https:\/\/www.h2kinfosys.com\/blog\/python-tools\/\">Python<\/a> alternative to Matlab is now seen as a modern and also complete programming language.<\/p>\n\n\n\n<p>Python distribution will come bundled with the NumPy module. NumPy can also be installed using its lighter version &#8211; a popular python package installer pip.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pip install NumPy:<\/h2>\n\n\n\n<p>We have the best way to enable NumPy. Install binary packages to the operating system. These binaries will contain full scipy stack.<\/p>\n\n\n\n<p>Windows<\/p>\n\n\n\n<p>Python(x,y) is a free python distribution with scipy stack and spyder IDE for windows OS.<\/p>\n\n\n\n<p>Linux<\/p>\n\n\n\n<p>Package managers of respective Linux distributors which will be used to install one or more packages in scipy stack.<\/p>\n\n\n\n<p>For Ubuntu<\/p>\n\n\n\n<p>sudo apt-get install python-numpy&nbsp;<\/p>\n\n\n\n<p>python-scipy python-matplotlib ipython ipython notebook python-pandas&nbsp;<\/p>\n\n\n\n<p>python-sympy python-nose<\/p>\n\n\n\n<p><strong>How to install NumPy?<\/strong><\/p>\n\n\n\n<p>The core python will be installed with distutils and the Zlib module should be enabled.GNU gcc&nbsp; C compiler must be available.<\/p>\n\n\n\n<p>To install NumPy we have to run the following command<\/p>\n\n\n\n<p>Python setup.py install<\/p>\n\n\n\n<p>To test whether the NumPy module is properly installed we try to import it with a python prompt.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;import numPy<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumPy packages will be imported by the syntax import numPy as np<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">NumPy-Ndarray object:<\/h2>\n\n\n\n<p>The most important object that will be defined in NumPy is an N-dimensional array type that will be called ndarray. It will describe the collection of items of the same type. Items in the collection can be accessed using zero-based index. Any item extracted from ndarray object that is represented by the python object is one of the scalar types.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/FYPXpLP1kcUw6133MV2JF-JgjNpqfQ8rS3m81csosaaKYSRD7amaHPfrAk-YZwLa9uiE_T9NMBT5x001CXL2tIf7xXJg1k7ZN4LZ1XNvPeIeggLBoXvO6bvyuRyotjoF9jZ6J6wE_dUG39s3K1Vbhw\" alt=\"Ndarray\" width=\"834\" height=\"308\" title=\"\"><\/figure>\n\n\n\n<p>An instance of ndarray class will be built by different array creation routines. The most fundamental ndarray will be developed by using an array function in the NumPy that follows as<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numpy.array&nbsp;<\/p>\n\n\n\n<p>It will develop an ndarray from any object exposing an array interface, or any method that will return an array.<\/p>\n\n\n\n<p>There are many constructors which will take the parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Object- Any object exposing the array interface method returns an array or any sequence.<\/li>\n\n\n\n<li>dtype- That is desired data type of array<\/li>\n\n\n\n<li>copy- By default the object will be copied.<\/li>\n\n\n\n<li>order- C or F column or A<\/li>\n\n\n\n<li>subok- That returned array is forced to be a base class array. Through, sub-classes passed through.<\/li>\n\n\n\n<li>ndadmin- It specifies minimum dimensions of the resultant array.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>import numpy as np&nbsp;<\/p>\n\n\n\n<p>a = np.array([2,3,5])&nbsp;<\/p>\n\n\n\n<p>print a<\/p>\n\n\n\n<p>Output<\/p>\n\n\n\n<p>[2,3,5]<\/p>\n\n\n\n<p>The ndarray object consists of a contiguous one-dimensional segment of computer memory, integrated with an indexing scheme that maps each item to a location in the memory block.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Numpy data types:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>bool_ : Boolean will be stored in bytes<\/li>\n\n\n\n<li>int_: The default integer type<\/li>\n\n\n\n<li>intc: identical to C int<\/li>\n\n\n\n<li>intp: Integer used for indexing<\/li>\n\n\n\n<li>int8: Byte<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Data Type objects:<\/h2>\n\n\n\n<p>A data type objects describes interpretation of fixed block of memory corresponding to an depending on the following aspects<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>&nbsp;Type of the data<\/li>\n\n\n\n<li>&nbsp;Size of the data<\/li>\n\n\n\n<li>&nbsp;Byte order<\/li>\n\n\n\n<li>&nbsp;The structured type,the names of fields, data type of all fields and part of the memory block taken by each field.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Questions<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>What is Numpy?<\/li>\n\n\n\n<li>What&nbsp; are the advantages of Numpy?<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>NumPy is a python package. It will stand for Numerical Python. This is considered as a library consisting of multidimensional array objects and also a collection of routines for managing arrays. The ancestor of Numpy was developed by Jim Hugunin. There are other packages Numarray also developed that have some additional functionalities. Operations using Numpy: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12825,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[342],"tags":[1345],"class_list":["post-12794","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials","tag-numpy"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/12794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=12794"}],"version-history":[{"count":1,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/12794\/revisions"}],"predecessor-version":[{"id":30543,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/12794\/revisions\/30543"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/12825"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=12794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=12794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=12794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}