Sideway
output.to from Sideway
Draft for Information Only

Content

NumPy
 Installation
  Conda
  PIP
  Anaconda
 Numpy Objects
  Array Objects
   ndarray Object
    Examples
   Array Scalars
    Examples
   Data type objects
    Examples
    Examples
  Constants
 Source and Reference

NumPy

NumPy is a Python package with well-optimized C core. 
NumPy provides powerful N-dimensional array computing through the using of concepts of vectorization, indexing, and broadcasting. Besides, Numpy also offers comprehensive mathematical functions for numerical computing.
Fast and versatile, the NumPy vectorization, indexing, and broadcasting concepts are the de-facto standards of array computing today.

Installation

The only prerequisite for installing NumPy is Python itself.

Conda

# Best practice, use an environment rather than install in the base env
conda create -n my-env
conda activate my-env
# If you want to install from conda-forge
conda config --env --add channels conda-forge
# The actual install command
conda install numpy

PIP

pip install numpy

Anaconda

The installation of Anaconda will also installs Numpy and some other useful tools and packages.

Numpy Objects

Working data of NumPy is stored in an N-dimensional array object. image

Array Objects

ndarray Object

The N-dimensional array, ndarray, is a multidimensional container of items of the same type and size. Different ndarrays can share th same data as usual. That is an ndarray can be a view to another ndarray. The typical characteristics of a ndarray are dtype and shape
Examples
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x=[[1,2,3],[4,5,6],[7,8,9]]
>>> x
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> type(x)
<class 'list'>
>>> import numpy as np
>>> x=np.array(x)
>>> type(x)
<class 'numpy.ndarray'>
>>> x.dtype
dtype('int32')
>>> x.shape
(3, 3)
>>>

Array Scalars

A array scalar is the basic array unit element of a ndarray. Array scalars have the same attributes and methods as ndarrays.
Examples
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> x=np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> x.shape
(3, 3)
>>> x.dtype
dtype('int32')
>>> x[0,0]
1
>>> x[0,0].shape
()
>>> x[0,0].dtype
dtype('int32')
>>>

Data type objects

A data type object is used to describe how the bytes in the fixed-size block of memory corresponding to an array item of a ndarray should be interpreted.
Examples
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> x=np.array([3])
>>> x.dtype
dtype('int32')
>>>
>>> np.int32
<class 'numpy.int32'>
>>>
>>> dt=np.dtype('int32')
>>> dt.name
'int32'
>>> dt.itemsize
4
>>> dt.byteorder
'='
>>> dt.kind
'i'
>>>
Examples
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> dt = np.dtype([('string', np.unicode_, 16), ('numberpair', np.float64, (2,))
])
>>> dt
dtype([('string', '<U16'), ('numberpair', '<f8', (2,))])
>>> dt['string']
dtype('<U16')
>>> dt['numberpair']
dtype(('<f8', (2,)))
>>>
>>> x = np.array([('asdf', (1,2)), ('hjkl', (3,4))], dtype=dt)
>>> x.shape
(2,)
>>> x.dtype
dtype([('string', '<U16'), ('numberpair', '<f8', (2,))])
>>> type(x)
<class 'numpy.ndarray'>
>>> x[0]
('asdf', [1., 2.])
>>> x[0].shape
()
>>> x[0].dtype
dtype([('string', '<U16'), ('numberpair', '<f8', (2,))])
>>> type(x[0])
<class 'numpy.void'>
>>> x[0]['string']
'asdf'
>>> x[0]['string'].shape
()
>>> x[0]['string'].dtype
dtype('<U4')
>>> type(x[0]['string'])
<class 'numpy.str_'>
>>>

Constants

NumPy includes some common constants, such as infinity, e, pi, for floating-point arithmetic

Source and Reference

  • https://numpy.org/
  • https://numpy.org/install/
  • https://numpy.org/doc/stable/reference/index.html
  • https://numpy.org/doc/stable/index.html
  • https://en.wikipedia.org/wiki/NumPy

©sideway

ID: 220100007 Last Updated: 1/7/2022 Revision: 0


Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Set 1

Logic 1

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019