 1561007051

# Why Should We Use NumPy?

NumPy is one of the most powerful Python libraries. This article will outline the core features of the NumPy library. It will also provide an overview of the common mathematical functions in an easy-to-follow manner.

If you want to understand everything about Python programming language

### What is NumPy?

• NumPy is an open source numerical Python library.
• NumPy contains a multi-dimentional array and matrix data structures.
• It can be utilised to perform a number of mathematical operations on arrays such as trigonometric, statistical and algebraic routines.
• NumPy is an extension of Numeric and Numarray.
• The library contains a large number of mathematical, algebraic and transformation functions .
• It also contains random number generators.
• NumPy is a wrapper around a library implemented in C.
• Pandas objects heavily relies on NumPy objects. Pandas extends Numpy.

### How Do I Install Numpy?

Use pip to install NumPy package:

``````pip install numpy

``````

SciPy stack also contains the NumPy packages Photo by Chris Ried on Unsplash

Pandas and Numpy complement each other and are the two most important Python libraries.

If you want to understand how Pandas work then please have a look at

### What Are The Most Important Numpy Data Types?

There are a large number of NumPy objects available:

#### One Dimensional Array

One of the most important objects are N-dimensional array type known as ndarray. All of the items that are stored in ndarray are required to be of same type.

An array contains a collection of objects of same type such as integers.

Think of an one dimensional array as a column or a row of a table with one or more elements: To create an array:

``````import numpy as np
a = np.array([1,2,3])

``````

#### Multi-Dimensional Array

A multidimentional array has more than one column.

Imagine an Excel Spreadsheet — it has columns and row. Each column can be considered as a dimension. This is a 2-D Array. We can instantiate an array object:

``````numpy.array([,.,.,.,])
e.g.
numpy.array([1,2]) #1D
numpy.array([[1,2],[10,20]]) #2D
#For complex types
numpy.array([1,2], dtype=complex) #1D complex

``````

If you want to create a 3-D Array:

``````3DArray = np.random.randint(10, size=(3, 4, 5))

``````

There are also other types available such as:

1. Boolean
2. Integer (signed and unsigned)
3. Float
4. Complex

### Different Ways To Create An Array

There are a number of different ways to create an array. This section will provide an overview of the most common methodologies:

1. If you want to create an array without any element:
``````numpy.empty(2) #this will create 1D array of 2 elements
numpy.empty(2,3) #this will create 2D array (2 rows, 3 columns each)

``````

2. If you want to create an array with 0s:

``````numpy.zeros(2) #it will create an 1D array with 2 elements, both 0
#Note the parameter of the method is shape, it could be int or a tuple

``````

3. If you want to create an array with 1s:

``````numpy.ones(2) # this will create 1D array with 2 elements, both 1

``````

4. If you want to create a Numpy array from Python sequence of elements:

``````numpy.asarray([python sequence]) #e.g. numpy.asarray([1,2])

``````

5. A text can be created as an array:

``````numpy.frombuffer('hi')
#frombuffer() takes in any object that exposes buffer interface

``````

We can pass in dtype parameter, default is float.

6. If you want to create a range of elements:

``````import numpy as np
array = np.arange(3)
#array will contain 0,1,2

``````

7. If you want to create an array with values that are evenly spaced:

``````numpy.arange(first, last, step, type)
#without last, step and type, the function behaves like arange()
e.g. to create 0-5, 2 apart
numpy.array(0,6,2) will return [0,2,4]

``````

8. If you want to create an array where the values are linearly spaced between an interval then use:

``````numpy.linspace(first, last, number)
e.g.
numpy.linspace(0,10,5) will return [0,2.5,5,7.5,10]

``````

9. If you want to create an array where the values are log spaced between an interval then use:

``````numpy.logspace(first, end, number)

``````

Any base can be specified, Base10 is the default.

10. Random number generation

Use the random module of numpy for uniformly distributed numbers:

``````np.random.rand(3,2) #3 rows, 2 cols

``````

``````np.append(a, [1,2]) #adds 1,2 at the end
#insert can also be used if we want to insert along a given index

``````

To delete elements:

``````np.delete(array, 1) #1 is going to be deleted from the array

``````

Sorting

To sort an array, call the sort(array, axis, kind, orderby) function:

``````np.sort(array1, axis=1, kind = 'quicksort', order ='column name')

`````` Photo by Mikael Kristenson on Unsplash

### NumPy Array Functions And Attributes

An ndarray object has a number of attributes, such as:

1. shape: To find the dimensions (numbers of column/row) of an array:
``````array = np.array([[..],[..]])
array.shape

``````

You can change the shape (resize) an array by setting the shape property:

``````array.shape = (1,2) #1 row, 2 columns

``````

2. resize(x,y) can also be used to resize an array

3. If you want to find the number of dimensions of an array:

``````array.dim

``````

4. If you want to find length of each element of an array:

``````array.itemsize

``````

It will then return the length of an element in bytes.

5. If you want to slice a subset of an array:

``````array = np.arange(100)
#Get 3rd element:
array
#Get items within indexes
array[3:5] #3 is start, 5 is end
#Get 3-10 element, step size 4 increments:
array[2:9:4]
#Get all elements from 2nd element onwards
array[1:]
#Can also pass in N-Dimensional Index
array[[0,1],[1,2]]

``````

6. Conditions In Array Slicing

We can pass in boolean operators e.g.

Get all NAN elements

``````array[np.isnan(array)]

``````

where() can be used to pass in boolean expressions:

``````np.where(array > 5) # will return all elements that meet the criteria

``````

When a mathematical operation is performed on two arrays of different sizes then the smaller array is broadcasted to the size of the larger array:

``````bigger_array = arange(5,3) #5 rows, 3 columns array
smaller_array = arange(5) #5 rows, 1 column array
final_array = bigger_array + smaller_array

``````

8. Transposing Array

``````array.T
rollaxis, swapaxes, transpose are also available transpose functions.

``````

9. To join arrays:

``````np.concatenate(a,b)
np.stack(a,b)
np.hstack(a,b)
np.vstack(a,b)

``````

10. String Operations

A large number of string operations can be utilised e.g.

``````add(), upper(), lower(), replace() etc.

``````

11. To create a deep copy of numpy array:

``````new_array = np.copy(array)

``````

### Mathematical Functions

Numpy offers a range of powerful Mathematical functions such as

#### Add, Subtract, Multiple, Divide, Power, Mod

To perform basic arithmetic functions:

``````np.add(array1, array2)
np.subtract(array1, array2)
np.multiply(array1, array2)
np.divide(array1, array2)
np.pow(array1, array2)
np.pow(array1, integer)
#to get remainder
np.mod(array1, array2)
np.remainder(array1, array2)

``````

#### Rounding, Ceil, Floor

To change the precision of all elements of an array:

``````np.around(array, 4) # 4dp
np.ceil(array) #1.8 will become 2
np.floor(array) #1.8 will become 1

``````

#### Trigonometric

``````array = np.arange(10)
np.sin(array)
np.cos(array)
np.tan(array)
np.arcsin(array)
np.arcos(array)
np.arctan(array)

``````

A number of complex number functions can also be applied such as getting real or imaginary parts of an array with complex numbers.

#### Statistical

There are also a large number of statistical functions available:

``````np.amin(array1, axis) #min in the axis
np.amax(array1, axis) #max in the axis
np.percentile(array1, percentile)
np.median(), np.st(), np.average(), np.mean(), np.var()

``````

#### Algebra

Numpy contains a module which is known as linalg. It is rich with a number of algebraic functions:

``````1. dot() #dot product of two arrays
2. inner() #inner product of two arrays
3. determinant() #determinant of an array
4. solve() #solves matrix equation
5. inv() #inverse of matrix
6. matmul() #matrix product of two arrays

``````

### Summary

This article provided an overview of the core functionalities of the NumPy library. Since NumPy was incorporated with the features of Numarray in 2005, it has gained huge popularity and is considered to be one of the key Python libraries to use.

The article outlined key functions and attributes of NumPy array.

Please let me know if you have any feedback, what your favourite NumPy features are and if you like these types of articles to be blogged in the future.

Hope it helps

#numpy #python #data-science #machine-learning

## Buddha Community  1595235180

## NumPy Features - Why we should use Numpy?

Welcome to DataFlair!!! In this tutorial, we will learn Numpy Features and its importance.

NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays

NumPy (Numerical Python) is an open-source core Python library for scientific computations. It is a general-purpose array and matrices processing package. Python is slower as compared to Fortran and other languages to perform looping. To overcome this we use NumPy that converts monotonous code into the compiled form. #### NumPy Features

These are the important features of NumPy:

#### 1. High-performance N-dimensional array object

This is the most important feature of the NumPy library. It is the homogeneous array object. We perform all the operations on the array elements. The arrays in NumPy can be one dimensional or multidimensional.

#### a. One dimensional array

The one-dimensional array is an array consisting of a single row or column. The elements of the array are of homogeneous nature.

#### b. Multidimensional array

In this case, we have various rows and columns. We consider each column as a dimension. The structure is similar to an excel sheet. The elements are homogenous.

#### 2. It contains tools for integrating code from C/C++ and Fortran

We can use the functions in NumPy to work with code written in other languages. We can hence integrate the functionalities available in various programming languages. This helps implement inter-platform functions.

#numpy tutorials #features of numpy #numpy features #why use numpy #numpy 1595235240

## NumPy Applications - Uses of Numpy

In this Numpy tutorial, we will learn Numpy applications.

NumPy is a basic level external library in Python used for complex mathematical operations. NumPy overcomes slower executions with the use of multi-dimensional array objects. It has built-in functions for manipulating arrays. We can convert different algorithms to can into functions for applying on arrays.NumPy has applications that are not only limited to itself. It is a very diverse library and has a wide range of applications in other sectors. Numpy can be put to use along with Data Science, Data Analysis and Machine Learning. It is also a base for other python libraries. These libraries use the functionalities in NumPy to increase their capabilities. #### 1. An alternative for lists and arrays in Python

Arrays in Numpy are equivalent to lists in python. Like lists in python, the Numpy arrays are homogenous sets of elements. The most important feature of NumPy arrays is they are homogenous in nature. This differentiates them from python arrays. It maintains uniformity for mathematical operations that would not be possible with heterogeneous elements. Another benefit of using NumPy arrays is there are a large number of functions that are applicable to these arrays. These functions could not be performed when applied to python arrays due to their heterogeneous nature.

#### 2. NumPy maintains minimal memory

Arrays in NumPy are objects. Python deletes and creates these objects continually, as per the requirements. Hence, the memory allocation is less as compared to Python lists. NumPy has features to avoid memory wastage in the data buffer. It consists of functions like copies, view, and indexing that helps in saving a lot of memory. Indexing helps to return the view of the original array, that implements reuse of the data. It also specifies the data type of the elements which leads to code optimization.

#### 3. Using NumPy for multi-dimensional arrays

We can also create multi-dimensional arrays in NumPy.These arrays have multiple rows and columns. These arrays have more than one column that makes these multi-dimensional. Multi-dimensional array implements the creation of matrices. These matrices are easy to work with. With the use of matrices the code also becomes memory efficient. We have a matrix module to perform various operations on these matrices.

#### 4. Mathematical operations with NumPy

Working with NumPy also includes easy to use functions for mathematical computations on the array data set. We have many modules for performing basic and special mathematical functions in NumPy. There are functions for Linear Algebra, bitwise operations, Fourier transform, arithmetic operations, string operations, etc.

#numpy tutorials #applications of numpy #numpy applications #uses of numpy #numpy 1620729846

## Why Use WordPress? What Can You Do With WordPress?

Can you use WordPress for anything other than blogging? To your surprise, yes. WordPress is more than just a blogging tool, and it has helped thousands of websites and web applications to thrive. The use of WordPress powers around 40% of online projects, and today in our blog, we would visit some amazing uses of WordPress other than blogging.
What Is The Use Of WordPress?

WordPress is the most popular website platform in the world. It is the first choice of businesses that want to set a feature-rich and dynamic Content Management System. So, if you ask what WordPress is used for, the answer is – everything. It is a super-flexible, feature-rich and secure platform that offers everything to build unique websites and applications. Let’s start knowing them:

1. Multiple Websites Under A Single Installation
WordPress Multisite allows you to develop multiple sites from a single WordPress installation. You can download WordPress and start building websites you want to launch under a single server. Literally speaking, you can handle hundreds of sites from one single dashboard, which now needs applause.
It is a highly efficient platform that allows you to easily run several websites under the same login credentials. One of the best things about WordPress is the themes it has to offer. You can simply download them and plugin for various sites and save space on sites without losing their speed.

2. WordPress Social Network
WordPress can be used for high-end projects such as Social Media Network. If you don’t have the money and patience to hire a coder and invest months in building a feature-rich social media site, go for WordPress. It is one of the most amazing uses of WordPress. Its stunning CMS is unbeatable. And you can build sites as good as Facebook or Reddit etc. It can just make the process a lot easier.
To set up a social media network, you would have to download a WordPress Plugin called BuddyPress. It would allow you to connect a community page with ease and would provide all the necessary features of a community or social media. It has direct messaging, activity stream, user groups, extended profiles, and so much more. You just have to download and configure it.
If BuddyPress doesn’t meet all your needs, don’t give up on your dreams. You can try out WP Symposium or PeepSo. There are also several themes you can use to build a social network.

3. Create A Forum For Your Brand’s Community
Communities are very important for your business. They help you stay in constant connection with your users and consumers. And allow you to turn them into a loyal customer base. Meanwhile, there are many good technologies that can be used for building a community page – the good old WordPress is still the best.
It is the best community development technology. If you want to build your online community, you need to consider all the amazing features you get with WordPress. Plugins such as BB Press is an open-source, template-driven PHP/ MySQL forum software. It is very simple and doesn’t hamper the experience of the website.
Other tools such as wpFoRo and Asgaros Forum are equally good for creating a community blog. They are lightweight tools that are easy to manage and integrate with your WordPress site easily. However, there is only one tiny problem; you need to have some technical knowledge to build a WordPress Community blog page.

4. Shortcodes
Since we gave you a problem in the previous section, we would also give you a perfect solution for it. You might not know to code, but you have shortcodes. Shortcodes help you execute functions without having to code. It is an easy way to build an amazing website, add new features, customize plugins easily. They are short lines of code, and rather than memorizing multiple lines; you can have zero technical knowledge and start building a feature-rich website or application.
There are also plugins like Shortcoder, Shortcodes Ultimate, and the Basics available on WordPress that can be used, and you would not even have to remember the shortcodes.

5. Build Online Stores
If you still think about why to use WordPress, use it to build an online store. You can start selling your goods online and start selling. It is an affordable technology that helps you build a feature-rich eCommerce store with WordPress.
WooCommerce is an extension of WordPress and is one of the most used eCommerce solutions. WooCommerce holds a 28% share of the global market and is one of the best ways to set up an online store. It allows you to build user-friendly and professional online stores and has thousands of free and paid extensions. Moreover as an open-source platform, and you don’t have to pay for the license.
Apart from WooCommerce, there are Easy Digital Downloads, iThemes Exchange, Shopify eCommerce plugin, and so much more available.

6. Security Features
WordPress takes security very seriously. It offers tons of external solutions that help you in safeguarding your WordPress site. While there is no way to ensure 100% security, it provides regular updates with security patches and provides several plugins to help with backups, two-factor authorization, and more.
By choosing hosting providers like WP Engine, you can improve the security of the website. It helps in threat detection, manage patching and updates, and internal security audits for the customers, and so much more.

#use of wordpress #use wordpress for business website #use wordpress for website #what is use of wordpress #why use wordpress #why use wordpress to build a website 1619660285

## Linear Algebra for Data Scientists with NumPy - Analytics India Magazine

A geek in Machine Learning with a Master’s degree in… ###### Delhivery Promises To Fly Charters With Oxygen Concentrators In India

NumPy is an essential Python library to perform mathematical and scientific computations. NumPy offers Python’s array-like data structures with exclusive operations and methods. Many data science libraries and frameworks, including PandasScikit-Learn, Statsmodels, Matplotlib and SciPy, are built on top of NumPy with Numpy arrays in their building blocks. Some frameworks, including TensorFlow and PyTorch, introduce NumPy arrays or NumPy-alike arrays as their fundamental data structure in the name of tensors. How NumPy becomes the base of Data Science computing system (source)

Data Science relies heavily on Linear Algebra. NumPy is famous for its Linear Algebra operations. This article discusses methods available in the NumPy library to perform various Linear Algebra operations with examples. These examples assume that the readers have a basic understanding of NumPy arrays. Check out the following articles to have a better understanding of NumPy fundamentals:

#developers corner #linear algebra #matrices #numpy #numpy array #numpy dot product #numpy matrix multiplication #numpy tutorial #svd #vectors 1596475108

## NumPy Copies and Views - Copy Vs View in NumPy

NumPy consists of different methods to duplicate an original array. The two main functions for this duplication are copy and view. The duplication of the array means an array assignment. When we duplicate the original array, the changes made in the new array may or may not reflect. The duplicate array may use the same location or may be at a new memory location. #### Copy or Deep copy in NumPy

It returns a copy of the original array stored at a new location. The copy doesn’t share data or memory with the original array. The modifications are not reflected. The copy function is also known as deep copy.

``````import numpy as np
arr = np.array([20,30,50,70])
a= arr.copy()
#changing a value in original array
arr = 100

print(arr)
print(a)
``````

Output

[100 30 50 70]

[20 30 50 70]

Changes made in the original array are not reflected in the copy.

``````import numpy as np
arr = np.array([20,30,50,70])
a= arr.copy()
#changing a value in copy array
a = 5

print(arr)
print(a)
``````

Output

[20 30 50 70]

[ 5 30 50 70]

Changes made in copy are not reflected in the original array

#numpy tutorials #numpy copy #numpy views #numpy