<jupyter_start><jupyter_text><jupyter_code>import numpy as np 
my_array = np.array([1,2,3,4,5]) # one dimensional array
my_array 
my_array.dtype
str_array  = my_array.astype(str)   #type casting 
str_array.dtype
for i in my_array:
  print(i*5)
for i in str_array:
  print(i*5)
lis = [1,2,3,4,5]
for i in lis:
  print(i*5)
dim_2array = np.array([[1,2,3,4,5],[7,8,9,10,11],[6,12,13,14,15]])
dim_2array
dim_2array.dtype
dim_2array.size
dim_2array.shape
dim_2array.ndim  #check the dimension
np.mean(dim_2array)
np.mean(dim_2array ,axis=0)  # mean column by column  #[14/3 , 22/ 3 , 25/3 , 28/3 , 31/3]
np.mean(dim_2array , axis = 1)   # mean row by row # [ 15/5 , 45/5 , 60/5]
dim_2array[0:2]    # print only first two rows  0,1 of array 
dim_2array[:2]  # print only first two rows  0,1 of array 
dim_2array[0:2 , : ] 
dim_2array[:2 , :2]   # print first two rows and column
dim_2array[:2 , :4]  #column-0,1,2,3   , row-0,1
dim_2array[:2 , :-1]  
dim_2array[:-1 , :2]  
dim_2array[:1 , :1]  #0,0
dim_2array[1: , :2]  
dim_2array[:1 , ::-1]  # first row in reverse order
dim_2array[0][::-1]  # first row in reverse order
cd /home/
np.savetxt('123.csv',dim_2array , delimiter =' , ')   # save dim_2array in the new file 123.csv 
np.save
np.genfromtxt('123.csv' , delimiter =' , ')
np.nan
?np.nan  # to show the help table
??np.nan
arr = np.array([1,2,3,4,5,np.nan])
arr
np.mean(arr)
np.isnan(arr)
arr2 = np.ma.masked_array(arr , np.isnan(arr))
arr2
import os
import matplotlib.pyplot as plt
cwd = os.getcwd()
cwd
mkdir /home/make       #create a directory inside a current working directory
image_dir = os.path.join(cwd , 'make')    # join the folder 'make' which contains all images in .jpg,.npg etc format
image_dir
red_image = []
green_image = []
for image in files:
  img = plt.imread(os.path.join(image_dir , image))
  reds = img[:,:,0]
  red_image.append(np.sum(reds))
  greens= img[:,:,1]
  green_image.append(np.sum(greens))
  
  
files = [f for f in os.listdir(image_dir) if f.endswith('.jpg')]
files
red_image
green_image<jupyter_output><empty_output><jupyter_text>To calculate the Ratio we need to convert datatype integer to float<jupyter_code>red_image = np.array(red_image , dtype='float')
red_image
green_image = np.array(green_image , dtype='float')
green_image
ratio = red_image/green_image
ratio
plt.subplot(211)
plt.plot(range(0,len(red_image)) , red_image ,'ro')
plt.plot(range(0,len(green_image)) , green_image,'go')
plt.subplot(211)
plt.plot(range(0,len(red_image)) , red_image)
plt.plot(range(0,len(green_image)) , green_image)
plt.subplot(211)
plt.plot(range(0,len(red_image)) , red_image )
plt.plot(range(0,len(green_image)) , green_image,'go')
plt.subplot(212)
plt.plot(range(0,len(ratio)) , ratio ,'ko' )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1588683351468988, 'fraction_numerical': 0.05513239027928908, 'mean_word_length': 4.880597014925373, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '307275', 'license': 'MIT', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1167, 'n_words': 253, 'path': 'numpy2.ipynb', 'repo_name': 'priyanshgupta1998/All_codes', 'size': '2757'}