NumPy in Python - MyPythonGuru

Jobs Search Portal and Learning point for Python,Data Science,AI,ML, Cloud and latest technologies.

Follow us on Facebook

Post Top Ad

Your Ad Spot

Sunday, September 1, 2019

NumPy in Python


. Introduction to Numpy

Numpy is a Library in python that specializes in dealing with multidimensional Arrays. The cool features of Numpy are :

Automatic Checking : Numpy nd Arrays automatically check the consistancy of data. For instance, it is not possible to have 1st row with 2 elements and 2nd row with 3 elements,

Contiguous Storage : Unlike Python Lists, Numpy stores the data in contiguous Memory Locations, leading to lesser Space.

Faster Vector Arithmatics : Because of contiguous storage, the operations are performed faster as compared to default Python Execution for Lists

How to import numpy:

To import numpy from python library we have to write below syntax using jupyter notebook.

import numpy as np

1.1 Initialization of 1D array in Python

Normally we know about Nd array when where degree of matrix is depend on n.
if N=1 then we say its 1D array,
N=2 then we can say its 2D array

A numpy array comes with 2 important state variables. Just like Python, it automatically detects dtype (if not mentioned).


  • dtype:   A data type object (an instance of numpy.dtype class) describes how the bytes in the fixed-size block of memory corresponding to an array item should be interpreted. It describes the following aspects of the data: Type of the data (integer, float, Pythonobject, etc.
         To know more about dtype: Click Here
  • shape : The shape attribute for numpy arrays returns the dimensions of the array. If Y has n rows and m columns, then Y.shape is (n,m) . So Y.shape[0] is n . shape is a tuple that gives dimensions of the array.
        Read More about Shape : shape in python 


Pandas dtypePython typeNumPy type
objectstrstring_, unicode_
int64intint_, int8, int16, int32, int64, uint8, uint16, uint32, uint64
float64floatfloat_, float16, float32, float64
boolboolbool_


1.1.1: Initialization from python List:

import numpy as np
numpy.array( list )

# v is variable

v = np.array([1,4,9,3,2])
print ('1D array in numpy is %s\n'%v)
print ('dtype of the numpy array is %s\n'%str(v.dtype))
print ('shape of the numpy array is %s\n'%v.shape)

once you will run the above code you will get below output

1D array in numpy is [1 4 9 3 2]

dtype of the numpy array is int32

shape of the numpy array is 5


1.1.2 Initialization via arange:

NumPy arange() is one of the array creation routines based on numerical ranges. It creates an instance of ndarray with evenly spaced values and returns the reference to it. You can define the interval of the values contained in an array, space between them, and their type with four parameters of arange() :numpy


numpy.arange([start, ]stop, [step, ] dtype=None)

v1 = np.arange(5)
print ('Creating a numpy array via arange (stop=5) : %s\n'%v1)

v2 = np.arange(2,5)
print ('Creating a numpy array via arange (start=2,stop=5) : %s\n'%v2)

v3 = np.arange(0,-10,-2)
print ('Creating a numpy array via arange (start=0,stop=-10,step=-2) : %s\n'%v3)

Output of print commands:

Creating a numpy array via arange (stop=5) : [0 1 2 3 4]
Creating a numpy array via arange (start=2,stop=5) : [2 3 4]
Creating a numpy array via arange (start=0,stop=-10,step=-2) : [ 0 -2 -4 -6 -8]


1.2. Initialization of 2D array in Python


When we talk about 2D array, it is important to note that Numpy stores Matrix in Row Major Format. Row major format means that the the complete row will be stored first and then the next row will be stored and so on. You can choose to store a matrix in column major format by mentioning order='F' on nd array creation, which means Column Major Format or Fortran Style Format.



1.2.1 Initialization from List of List


numpy.array ( object, dtype=None )


Here the matrix that we have taken is ( 2 rows,3 Column)

𝑚𝑎𝑡=[
142536]


pymat = [[1,2,3],[4,5,6]]
npmat = np.array(pymat)
print ('numpy matrix is \n%s\n'%npmat)
print ('Flattened version of numpy matrix is %s\n'%npmat.flatten())
# By flatten the matrix becomes row major 1D vector (This is the way in which a matrix is stored in memory).

Output Of above code will be:

numpy matrix is

[[1 2 3]
[4 5 6]]

Flattened version of numpy matrix is [1 2 3 4 5 6]


1.2.2 Initialization with zero/ones

numpy.zeros(shape, dtype=float)
numpy.ones(shape, dtype=float)

mat_zeros = np.zeros(shape=(3,5))
print ('Zeros Matris of shape %s is \n%s\n'%(mat_zeros.shape,mat_zeros))
mat_ones = np.ones(shape=(2,3))
print ('Ones Matris of shape %s is \n%s\n'%(mat_ones.shape,mat_ones))


Zeros Matris of shape (3, 5) is
[[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]]

Ones Matris of shape (2, 3) is
[[1. 1. 1.]
[1. 1. 1.]]


1.2.3 Initialization with Random Values

1.2.3.1 numpy.random.random(size=None,)--

This function Return random floats in the half-open interval [0.0, 1.0).

Results are from the “continuous uniform” distribution over the stated interval. To sample Unit
(a, b), b > a multiply the output of random_sample by (b-a) and add a:
(b - a) * random_sample() + a

Parameters: size : int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
Returns: out : float or ndarray of floats

Array of random floats of shape size (unless size=None, in which case a single float is returned).

Reference :  Scipy Tutorials

1.2.3.2 numpy.random.randint(low, high, size=None, dtype='I') : The value of matrix lies between low and high-1
1.2.3.3 numpy.random.randn(d0,d1,⋯,dnd0,d1,⋯,dn)




#Using numpy.random.random
mat1 = np.random.random(size=(3,4))
print ('matrix generated from numpy.random.random is \n%s\n'%mat1)
mat2 = np.random.randint(low=0,high=2,size=(3,4))
print ('matrix generated from numpy.random.random is \n%s\n'%mat2)
mat3 = np.random.randn(3,4)
print ('matrix generated from numpy.random.randn is \n%s\n'%mat3)

matrix generated from numpy.random.random is
[[0.40809381 0.92255528 0.26384768 0.18020434]
[0.78683826 0.51616332 0.20181108 0.44676456]
[0.40513581 0.41943719 0.14935848 0.49202397]]

matrix generated from numpy.random.random is
[[1 0 1 0]
[0 1 1 1]
[0 1 1 0]]

matrix generated from numpy.random.randn is
[[ 1.23093258 0.06762907 1.32948035 1.27069921]
[-1.55068329 -0.48071094 0.85203508 -1.90068409]
[-1.94335643 0.12680395 0.06573786 -0.66923407]]


1.3. Slicing and Indexing in Numpy

Just like python, numpy also has 0 indexing. Let us see some of the commonly used slicing techniques .
Generic Slicing Operation : [start]:[end]:[jump]
Only jump ::2
Only end :5
Start and jump 2::-1
End and Jump :5:2
Start, end and jump 2:7:3

1.3.1 Remove n elements

vec[:-n]

To remove n element from an array we use [-n] notation where n is the number of element which should be removed from nd array.

in below example we have a vector with name vec having range 10 and we have to remove 3 element from nd array vector, since we have to remove so we will use minus or hyphen sign just before the numerical value.

vec = np.arange(10)
vec1 = vec[:-3]
print ('Result of removing last 3 elements from range(10) : \n%s\n'%vec1)

output: 

Result of removing last 3 elements from range(10) :
[0 1 2 3 4 5 6]


1.3.2 Access elements at even indices in a 1D array

vec[::2]

suppose we have created a 1D array with name vec1 and pass parameter a per example given below.
where vec1 value will be jump with the iterval of 3.

vec1 = np.arange(0,20,3)
print ('Original array is %s\n'%vec1)
# above code will recturn the value between 0 to 20 with a jump of 3.
vec2 = vec1[::2]
print ('Elements at even indices are %s\n'%vec2)
Original array is [ 0 3 6 9 12 15 18]

Elements at even indices are [ 0 6 12 18]


1.3.3 Access elements at indices in reverse order

vec[::-1]

vec1 = np.arange(0,20,3)
print ('Original array is %s\n'%vec1)
vec2 = vec1[::-1]
print ('Elements for indices in reverse is %s\n'%vec2)


Original array is [ 0 3 6 9 12 15 18]

Elements for indices in reverse is [18 15 12 9 6 3 0]


1.3.4 Access elements present for a range of indices:

vec[a:b]

vec1 = np.arange(0,20,3)
print ('Original array is %s\n'%vec1)
vec2 = vec1[2:5]
print ('Elements for indices 2:5 is %s\n'%vec2)
Original array is [ 0 3 6 9 12 15 18]

Elements for indices 2:5 is [ 6 9 12]


1.3.5 Access a particular set of index given by a list:

vec[idxlist]


 idx=[0,1,5]
vec1 = np.arange(0,20,3)
print ('Original array is %s\n'%vec1)
vec2 = vec1[idx]
print ('Subarray constructed by indices %s is %s\n'%(idx,vec2))

Original array is [ 0 3 6 9 12 15 18]

Subarray constructed by indices [0, 1, 5] is [ 0 3 15]


1.3.6 Creating a submatrix

mat = np.random.randint(0,6,(3,5))
# Create a submatrix with first 2 rows and last 2 columns
submat1 = mat[0:2,-2:]
print ('Original Matrix is \n%s\n'%mat)
print ('Sub Matrix with first 2 rows and last 2 columns is \n%s\n'%submat1)
submat2 = mat[:,3:0:-1]
print ('After flipping the columns of the matrix, it looks : \n%s\n'%submat2)
Original Matrix is
[[1 2 0 0 2]
[4 1 5 3 2]
[2 1 3 5 0]]

Sub Matrix with first 2 rows and last 2 columns is
[[0 2]
[3 2]]

After flipping the columns of the matrix, it looks :
[[0 0 2]
[3 5 1]
[5 3 1]]


1.3.7 Horizontal Matrix splitting


numpy.hsplit(ary, indices_or_sections)

hsplit basically splits a matrix across the horizontal plane based on the indices. Do note that the number of rows always remains constant in each section after the horizontal splitting.

mat = np.random.randint(0,6,(3,7))
sp1,sp2,sp3 = np.hsplit(mat,[4,6])
print ('Original matrix of shape %s, is \n%s\n'%(mat.shape,mat))
print ('First split of shape %s, is \n%s\n'%(sp1.shape,sp1))
print ('Second split of shape %s, is \n%s\n'%(sp2.shape,sp2))
print ('Third split of shape %s, is \n%s\n'%(sp3.shape,sp3))
Original matrix of shape (3, 7), is
[[5 4 1 2 1 5 2]
[1 5 5 5 0 5 3]
[2 0 1 5 4 4 4]]

First split of shape (3, 4), is
[[5 4 1 2]
[1 5 5 5]
[2 0 1 5]]

Second split of shape (3, 2), is
[[1 5]
[0 5]
[4 4]]

Third split of shape (3, 1), is
[[2]
[3]
[4]]


1.3.8 Vertical Matrix Splitting:


numpy.vsplit(ary, indices_or_sections)


vsplit is yet another operation which splits the matrix across the vertical plane based on the 'rowwise split-index array'. The number of columns always remain constant in each split.



mat = np.random.randint(0,6,(3,7))
sp1,sp2 = np.vsplit(mat,[1])
print ('Original matrix of shape %s, is \n%s\n'%(mat.shape,mat))
print ('First split of shape %s, is \n%s\n'%(sp1.shape,sp1))
print ('Second split of shape %s, is \n%s\n'%(sp2.shape,sp2))
Original matrix of shape (3, 7), is
[[5 2 1 1 0 5 5]
[5 3 0 1 5 2 1]
[5 5 4 2 2 1 0]]

First split of shape (1, 7), is
[[5 2 1 1 0 5 5]]

Second split of shape (2, 7), is
[[5 3 0 1 5 2 1]
[5 5 4 2 2 1 0]]


1.3.8 Vertical Matrix Splitting:

numpy.vsplit(ary, indices_or_sections)

vsplit is yet another operation which splits the matrix across the vertical plane based on the 'rowwise split-index array'. The number of columns always remain constant in each split.
In [134]:


mat = np.random.randint(0,6,(3,7))
sp1,sp2 = np.vsplit(mat,[1])
print ('Original matrix of shape %s, is \n%s\n'%(mat.shape,mat))
print ('First split of shape %s, is \n%s\n'%(sp1.shape,sp1))
print ('Second split of shape %s, is \n%s\n'%(sp2.shape,sp2))




Original matrix of shape (3, 7), is [[5 2 1 1 0 5 5] [5 3 0 1 5 2 1] [5 5 4 2 2 1 0]] First split of shape (1, 7), is [[5 2 1 1 0 5 5]] Second split of shape (2, 7), is [[5 3 0 1 5 2 1] [5 5 4 2 2 1 0]]




Class Assignment for 1.1 to 1.3
Create a matrix of size (2,3) with random binary values
Find the sum of all 2x2 blocks (overlapping) for a random integer matrix of size (3,5)


1.4. Understanding - Pass By Reference:

Just like python lists, Numpy also exhibits default pass-by-reference behavior
In [110]:


mat1 = np.random.random((2,3))
pt1 = mat1[0].__array_interface__['data'][0]
print ('Memory Location of mat1[0] is : %s\n'%pt1)
pt2 = mat1[1].__array_interface__['data'][0]
print ('Memory Location of mat1[1] is : %s\n'%pt2)
print ('Difference in Memory Location for 3 elements is : %s bytes\n'%(pt2-pt1))
print ('Memory jump = 8 bytes')





Memory Location of mat1[0] is : 2041724279440 Memory Location of mat1[1] is : 2041724279464 Difference in Memory Location for 3 elements is : 24 bytes Memory jump = 8 bytes



1.4.1 Experiment : Change the value of array by Reference:

def identity(elem):
return elem
v = np.array([1,2,3])
v1 = v # Copy by reference
v1[0]=10
print ('Value of v, after v1 is modified is %s\n'%v)
# Pass by Function
v = np.array([1,2,3])
v1 = identity(v) # Copy by reference
v1[0]=10
print ('Value of v after func(v) is modified is %s\n'%v)
v = np.array([1,2,3])
v1 = v.copy() # Copy by reference
v1[0]=10
print ('Value of v after v.copy() is modified is %s\n'%v)



Value of v, after v1 is modified is [10 2 3] Value of v after func(v) is modified is [10 2 3] Value of v after v.copy() is modified is [1 2 3]



1.4.2 Experiment : Change the value of matrices by Reference:


mat = np.array([[1,2,3],[4,5,6],[7,8,9]])
print ('Original Matrix is \n%s\n'%mat)

#1 Add 10 to all the even indexes in matrix
mat = np.array([[1,2,3],[4,5,6],[7,8,9]])
mat1 = mat[::2,::2]
mat1+=10
print (' Matrix with 10 added to even indices is \n%s\n'%mat1)
# Changes in mat1 are reflected in mat. This happens because the default assignment in numpy is 'pass by reference'




Original Matrix is [[1 2 3] [4 5 6] [7 8 9]] Matrix with 10 added to even indices is [[11 13] [17 19]]





Note : mat1+=10 is different from mat1=mat1+10, as a new space is allocated for mat1 in the latter case.


1.5 Broadcast Operation in Numpy:

Broadcast Operation is like a razor-sharp knife, to be used with great care. It is a way to broadcast data of lower or same dimension onto another ndarray. It is similar to map operation in python, scala, hadoop. Broadcast rules are not limited to 2D array. There are extremely specific set of rules for nd-array broadcasting. You can visit numpy documentation on broadcasting to get the complete picture. However, we will be restricting the discussion to only 2D-matrices.


mat = np.random.randint(0,6,(3,5))
print ('mat is \n%s\n'%mat)
v = np.array([10,20,30,40,50])
print ('v is \n%s\n'%v)
print ('mat+1 is \n%s\n'%(mat+1)) # Similar behaviour in case of np.array([1])
print ('mat+v is \n%s\n'%(mat+v))
print ('mat*v is \n%s\n'%(mat*v))
print ('mat+mat is \n%s\n'%(mat+mat))
print ('mat*mat is \n%s\n'%(mat*mat))



mat is [[1 1 2 1 4] [4 2 1 3 5] [3 1 1 2 5]] v is [10 20 30 40 50] mat+1 is [[2 2 3 2 5] [5 3 2 4 6] [4 2 2 3 6]] mat+v is [[11 21 32 41 54] [14 22 31 43 55] [13 21 31 42 55]] mat*v is [[ 10 20 60 40 200] [ 40 40 30 120 250] [ 30 20 30 80 250]] mat+mat is [[ 2 2 4 2 8] [ 8 4 2 6 10] [ 6 2 2 4 10]] mat*mat is [[ 1 1 4 1 16] [16 4 1 9 25] [ 9 1 1 4 25]]



1.6 Matrix Operations:

There are two major matix Operations which are important for us.
Inner Product
Vector Vector
Matrix Vector
Matrix Matrix
Outer product
1.6.1 Inner Product

In terms of Inner Product or Dot product, <v,w> will be be nothing but sum of element wise product.
<𝑣,𝑤>=∑𝑣𝑖∗𝑤𝑖=[𝑣0𝑣1⋯𝑣𝑛]𝑤0𝑤1⋯𝑤𝑛<v,w>=∑vi∗wi=[v0v1⋯vn][w0w1⋯wn]So, the dot product between vector 𝑣=[1,2,3]v=[1,2,3] and 𝑤=[2,4,6]w=[2,4,6] will be
1∗2+2∗4+3∗62+8+18281∗2+2∗4+3∗62+8+1828
We will be covering matrix matrix multiplication in much depth in next-to-next chapter, but you can take it for granted as of now.


1.6.2 Outer Product

The outer product on other end is
𝑣0𝑣1⋯𝑣𝑛[𝑤0𝑤1⋯𝑤𝑛]=𝑣0𝑤0⋮𝑣𝑖𝑤0⋮𝑣𝑛𝑤0⋯⋯⋯𝑣0𝑤𝑗⋮𝑣𝑖𝑤𝑗⋮𝑣𝑛𝑤𝑗⋯⋯⋯𝑣0𝑤𝑛⋮𝑣𝑖𝑤𝑛⋮𝑣𝑛𝑤𝑛[v0v1⋯vn][w0w1⋯wn]=[v0w0⋯v0wj⋯v0wn⋮⋮⋮viw0⋯viwj⋯viwn⋮⋮⋮vnw0⋯vnwj⋯vnwn]


In [11]:





mat = np.arange(9).reshape(3,3)
vec1 = np.array([1,2,3])
vec2 = np.array([2,4,6])
print ('Vector v1 is %s\n'%vec1)
print ('Vector v2 is %s\n'%vec2)
print ('Vector Vector dot product is <v1,v2> is %s\n'%np.dot(vec1,vec2))
print ('---------------\n')

print ('Matrix is\n%s\n'%mat)
print ('Vector v2 is\n%s\n'%vec1)

print ('Matrix Vector product is <mat,vec1> is \n%s\n'%np.dot(mat,vec1))
print ('Matrix Matrix multiplication is <mat,mat> is \n%s\n'%np.dot(mat,mat))
print ('---------------\n')

print ('Vector v1 is %s\n'%vec1)
print ('Vector v2 is %s\n'%vec2)
print ('Vector Vector outer product is <v1,v2> is \n%s\n'%np.outer(vec1,vec2))





Vector v1 is [1 2 3] Vector v2 is [2 4 6] Vector Vector dot product is <v1,v2> is 28 --------------- Matrix is [[0 1 2] [3 4 5] [6 7 8]] Vector v2 is [1 2 3] Matrix Vector product is <mat,vec1> is [ 8 26 44] Matrix Matrix multiplication is <mat,mat> is [[ 15 18 21] [ 42 54 66] [ 69 90 111]] --------------- Vector v1 is [1 2 3] Vector v2 is [2 4 6] Vector Vector outer product is <v1,v2> is [[ 2 4 6] [ 4 8 12] [ 6 12 18]]



1.7 Statistical Functions
np.mean(data,axis=0)
np.var(data,axis=0)
np.sum(data,axis=0)
np.max(data,axis=0)
np.min(data,axis=0)
np.percentile(data, percentage,axis=0)
In [40]:






mat = np.arange(9).reshape((3,3))
print ('Original matrix is \n%s\n'%mat)
print ('Overall mean of matrix is \n%s\n'%np.mean(mat))
print ('Row mean of matrix is \n%s\n'%np.mean(mat, axis=0))
print ('Column mean of matrix is \n%s\n'%np.mean(mat, axis=1))
print ('---------------------------\n')
print ('Overall varience of matrix is %s\n'%np.var(mat))
print ('Overall sum of matrix is %s\n'%np.sum(mat))
print ('Overall min of matrix is %s\n'%np.min(mat))
print ('Overall max of matrix is %s\n'%np.max(mat))

print ('-------------------------------------\n')
marks = np.array([30,31,32,40,90,95,97,98,99,100])
print ('Marks = %s\n'%marks)
print ('Overall 30 percent quantile of marks is %s\n'%(str(np.percentile(marks,30))))





Original matrix is [[0 1 2] [3 4 5] [6 7 8]] Overall mean of matrix is 4.0 Row mean of matrix is [3. 4. 5.] Column mean of matrix is [1. 4. 7.] --------------------------- Overall varience of matrix is 6.666666666666667 Overall sum of matrix is 36 Overall min of matrix is 0 Overall max of matrix is 8 ------------------------------------- Marks = [ 30 31 32 40 90 95 97 98 99 100] Overall 30 percent quantile of marks is 37.599999999999994



1.8 Miscellenous Functions

In this section, we will be discussing some important miscellenous Functions which come in handy for matrix manipulation.
1.8.1 squeeze

numpy.squeeze(a,axis=None)
This function tries to reduce the excess dimensions which have only 1 element. If we print the shape of the ndary, these excess dimension will have a 1 in that particular dimension's index. For example, a nd-matrix with shape (1,2,3,1), has 0𝑡ℎ0th and 3𝑟𝑑3rd dimension as excess.
In [5]:





ndmat = np.zeros(shape=(1,2,3,1))
print ('Original Shape of ndmat is %s\n'%str(ndmat.shape))
ndmat1 = np.squeeze(ndmat)
print ('Shape of np.squeeze(ndmat) is %s\n'%str(ndmat1.shape))
ndmat2 = np.squeeze(ndmat,axis=3)
print ('Shape of np.squeeze(ndmat,axis=3) is %s\n'%str(ndmat2.shape))






Original Shape of ndmat is (1, 2, 3, 1) Shape of np.squeeze(ndmat) is (2, 3) Shape of np.squeeze(ndmat,axis=3) is (1, 2, 3)



1.8.2 transpose

numpy.transpose(a, axes=None)
This function reverses the axes for 2D array.
For multidimensional array, it permutes the matrix according to the axis argument
In [21]:





mat = np.zeros(shape=(2,3))
print ('Original Shape of 2D matrix is %s\n'%str(mat.shape))
mat_transpose = np.transpose(mat)
print ('Shape of np.transpose(mat) is %s\n'%str(mat_transpose.shape))
mat_transpose[1,0] = 1
print ('np.transpose is by yet again assignment by reference, as changes in transpose reflects in the original matrix\n')
print ('---------------------------------\n')
# NDimensional matrix
ndmat = np.zeros(shape=(2,3,4))
print ('Original Shape of nDimensional matrix is %s\n'%str(ndmat.shape))
ndmat_transpose = np.transpose(ndmat)
print ('Shape of np.transpose(ndmat) is %s\n'%str(ndmat_transpose.shape))
ndmat_special_transpose = np.transpose(ndmat, axes = [0,2,1])
print ('Shape of np.transpose(ndmat, axes=[0,2,1]) is %s\n'%str(ndmat_special_transpose.shape))





Original Shape of 2D matrix is (2, 3) Shape of np.transpose(mat) is (3, 2) np.transpose is by yet again assignment by reference, as changes in transpose reflects in the original matrix --------------------------------- Original Shape of nDimensional matrix is (2, 3, 4) Shape of np.transpose(ndmat) is (4, 3, 2) Shape of np.transpose(ndmat, axes=[0,2,1]) is (2, 4, 3)



Lab Practice Question:

Create a null array of size 10 but the fifth value which is 1
Reverse a above created array (first element becomes last)
Create a 3x3 matrix with values ranging from 0 to 8
Find indices of non-zero elements from [1,2,0,0,4,0]
Create a 3x3x3 array with random values
Create a 10x10 array with random values and find the minimum and maximum values
Create a random vector of size 30 and find the mean value
Create a 2d array with 1 on the border and 0 inside
Multiply a 5x3 matrix by a 3x2 matrix (real matrix product)
Extract the integer part of a random array
Create a 5x5 matrix with row values ranging from 0 to 4
Create a random vector of size 10 and sort it
Consider two random array A anb B, check if they are equal
How to tell if a given 2D array has null columns?
Considering a four dimensions array, how to get sum over the last two axis at once?
Consider an array of dimension (5,5,3), how to mulitply it by an array with dimensions (5,5)?
Extract all the contiguous 3x3 blocks from a random 10x10 matrix
Consider a 16x16 array, how to get the block-sum (block size is 4x4)?

Read more : Click Here





No comments:

Post Top Ad

Your Ad Spot