# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np

list1=[1,2,3,4]

array1=np.array(list1)

array1


list2=[11,22,33,44]

lists=[list1,list2]

lists


array2=np.array(lists)

array2


array2.shape

array2.dtype

np.zeros(5)

zeros=np.zeros(5)

zeros


zeros.dtype

ones=np.ones(5)

ones

ones=np.ones([4,4])

ones


empty=np.empty(5)

empty

iden=np.eye(5)

iden

np.arange(5)

np.arange(3,30)

np.arange(3,30,4)

# +
#########################################################################################
# -

5.0/2

arr1=np.array([[1,2,3,4],[8,9,10,11]])

arr1

arr1*arr1

arr1*2

arr1-arr1

arr1+1

1/arr1

arr1**3

# +
##################################################################################
# -

arr=np.arange(12)

arr

arr=np.arange(0,5)

arr

arr[3]

arr[1:4]

arr[0:4]

arr[0:4]=100

arr

arr=np.arange(11)

slice=arr[0:6]
slice

slice[:]=99

slice

arr

arr_copy=arr.copy()

arr_copy

slice_arr=arr_copy[0:6]

slice_arr

slice_arr[:]=80

slice_arr

arr_copy


arr

arr_2d=np.array(([5,10,15],[20,25,30],[35,40,45]))
arr_2d

arr_2d[1]

arr_2d[0]

arr_2d[0:2]

arr_2d[1][0]

arr_2d[:2,1:]

arr_2d[:2,:1]

arr2d=np.zeros((10,10))

arr2d

arr_length=arr2d.shape[1]

for i in range(arr_length):
    arr2d[i]=i

arr2d

arr2d[[2,6,3]]

# +
#######################################################################################
# -

arr=np.arange(50).reshape(5,10)

arr

arr.T

np.dot(arr.T,arr)

arr3d=np.arange(50).reshape((5,5,2))
arr3d

arr=np.array([[1,2,3]])
arr

arr.swapaxes(0,1)

# +
############################################################################################
# -

arr=np.arange(11)

np.sqrt(arr)

np.exp(arr)

A=np.random.rand(10)

A

B=np.random.rand(10)
B

np.add(A,B)

np.maximum(A,B)

np.minimum(A,B)

# +
#############################################
# -

import matplotlib.pyplot as plt
# %matplotlib inline

points = np.arange(-5,5,0.01)

dx,dy=np.meshgrid(points,points)

dx

dy


z=(np.sin(dx)+np.sin(dy))

z

plt.imshow(z)

plt.imshow(z)
plt.colorbar
plt.title("sinx + siny")

# +
A=np.array([1,2,3,4])

B=np.array([100,200,300,400])
# -

C=np.array([True,True,False,False])

ans=[(A_val if cond else B_val) for A_val,B_val,cond in zip(A,B,C)]

ans

ans2=np.where(C,A,B)
ans2

arr= np.random.rand(5,5)

arr

np.where(arr<0.5,0,arr)

arr=np.array([[1,2,3],[4,5,6],[7,8,9]])
arr

arr.sum()

arr.sum(1)

arr.mean(1)

arr.mean()

arr.std()

arr.var()

bool_arr=np.array([True,False,True])

bool_arr

bool_arr.any()

bool_arr.all()

arr=np.random.rand(5)

arr


arr.sort()

arr

countries=(['USA','USA','FRANCE','GERMANY'])

np.unique(countries)

np.in1d(['FRANCE','USA','INDIA'],countries)

# +
####################################################################################
# -

arr=np.arange(5)

np.save('my array',arr)

arr=np.arange(10)
arr

np.load('my array.npy')



StarcoderdataJupyterScriptsDedupFiltered