<jupyter_start><jupyter_text>ARRAY<jupyter_code>from array import *
vals=array('i',[5,9,8,4,2])
print(vals)
print(vals.buffer_info())
print(vals.typecode)
print(vals.append(5))
print(vals.remove(9))
print(vals.reverse())
vals.reverse()
print(vals)
print(vals[0])
from array import *
vals=array('i',[5,9,-8,4,2])
for i in range(5):
  print(vals[i])
from array import *
vals=array('i',[5,9,-8,4,2])
for i in range(len(vals)):
  print(vals[i])
from array import *
vals=array('i',[5,9,-8,4,2])
for e in vals:
  print(e)
from array import *
vals=array('u',['a','e','i'])
for e in vals:
  print(e)
from array import *
vals=array('i',[5,9,8,4,2])
newArr=array(vals.typecode,(a for a in vals))
for e in newArr:
  print(e)
from array import *
vals=array('i',[5,9,8,4,2])
newArr=array(vals.typecode,(a*a for a in vals))
for e in newArr:
  print(e)
from array import *
vals=array('i',[5,9,8,4,2])
newArr=array(vals.typecode,(a for a in vals))
i=0
while i<len(newArr):
  print(newArr[i])
  i+=1
#user input array
from array import *
arr=array('i',[])
n=int(input("enter length of array"))
for i in range(n):
    x=int(input("enter value"))
    arr.append(x)
print(arr)    

from array import *
arr=array('i',[])
n=int(input("enter length of array"))
for i in range(n):
    x=int(input("enter value"))
    arr.append(x)
print(arr)
val=int(input("enter value for search"))
k=0
for e in arr:
  if e==val:
    print(k)
    break
  k+=1
print(arr.index(val))<jupyter_output>enter length of array4
enter value5
enter value1
enter value2
enter value3
array('i', [5, 1, 2, 3])
enter value for search2
2
2<jupyter_text>MULTIDIMENSIONAL ARRAY<jupyter_code>pip install numpy

from numpy import *
#In numpy mention the type at the end.
arr=array([1,2,3,4,5],int)
print(arr)<jupyter_output>[1 2 3 4 5]<jupyter_text>DIFFERENT WAYS OF CREATING ARRAY IN NUMPY:---1)array()2)linspace()3)logspace()4)arange()5)zeros()6)ones()<jupyter_code>from numpy import *
arr=array([1,2,3,4,5])
print(arr)
print(arr.dtype)
from numpy import *
arr=array([1,2,3,4,5.0])#here allthe values are convered into float
print(arr)
from numpy import *
arr=linspace(0,15,16)#linspace(start,stop,steps)
print(arr)
#here all the values are float because we are breaking range partwise.So, normally if we divide in part,we can get a float value.
from numpy import *
arr=linspace(0,15,20)
print(arr)
from numpy import *
arr=linspace(0,15) #If we don't specify steps,it will by default divide it into 50 parts.
print(arr)
from numpy import *
arr=arange(1,15,2) #arange(first elem,last elem,steps)
print(arr)
from numpy import *
arr=logspace(1,40,5) #In logspace the spacing b/w 2 numbers will depend upon the log of it.
print(arr)
from numpy import *
arr=zeros(5,int) #zeros(size,dtype)
print(arr)
from numpy import *
arr=ones(5,int)
print(arr)<jupyter_output>[1 1 1 1 1]<jupyter_text>Copying an array in python<jupyter_code>from numpy import *
arr=array([1,2,3,4,5])
arr=arr+5
print(arr)
from numpy import *
arr1=array([1,2,3,4,5])
arr2=array([6,1,9,3,2])
arr3=arr1 + arr2
print(arr3)
from numpy import *
arr=array([1,2,3,4,5])
print(sin(arr))
print(cos(arr))
print(max(arr))
print(log(arr))
print(unique(arr))
print(sqrt(arr))
from numpy import *
arr1=array([2,6,8,1,3])
arr2=arr1 #here both points to same memory location i.e;aliasing
print(arr1)
print(arr2)
from numpy import *
arr1=array([2,6,8,1,3])
arr2=arr1.view()
print(arr1)
print(arr2)
print(id(arr1))
print(id(arr2))<jupyter_output>[2 6 8 1 3]
[2 6 8 1 3]
140684096951280
140684096447472<jupyter_text>Shallow Copy(both array will depend on each other)<jupyter_code>from numpy import *
arr1=array([2,6,8,1,3])
arr2=arr1.view()
arr1[1]=7
print(arr1)
print(arr2)
print(id(arr1))
print(id(arr2))<jupyter_output>[2 7 8 1 3]
[2 7 8 1 3]
140684096292064
140684097179520<jupyter_text>Deep Copy(both array is independent of each other)<jupyter_code>from numpy import *
arr1=array([2,6,8,1,3])
arr2=arr1.copy()
arr1[1]=7
print(arr1)
print(arr2)<jupyter_output>[2 7 8 1 3]
[2 6 8 1 3]<jupyter_text>working with Mtrix in Python<jupyter_code>from numpy import *
arr1=array([
             [1,2,3],    
            [4,5,6]
         ])
print(arr1)

print(arr1.dtype)
print(arr1.ndim)#gives dimenions/ranking
print(arr1.shape)#gives no. of rows and columns
print(arr1.size)#size of entire block
from numpy import *
arr1=array([
             [1,2,3],    
            [4,5,6]
         ])
arr2=arr1.flatten()#converts 2D array into 1D array
print(arr2)
from numpy import *
arr1=array([
             [1,2,3,6,2,9],
            [4,5,6,7,5,3]       

           ])
arr2=arr1.flatten()
arr3=arr2.reshape(3,4)#reshape(rows,columns)   #converts 1d array into 2d array
print(arr3)
arr3=arr2.reshape(2,2,3)#create a 3D array & that 3D array will have 2 2d array & each 2D array will have 2 1D array & each 1D array will have 3 values
print(arr3)<jupyter_output>[[[1 2 3]
  [6 2 9]]

 [[4 5 6]
  [7 5 3]]]<jupyter_text>Matrices<jupyter_code>from numpy import *
arr1=array([
             [1,2,3],    
            [4,5,6]
         ])
m=matrix(arr1)
print(m)
#output looks same but with this m we can perform more operations
from numpy import *
m=matrix('1 2 3 6 ; 4 5 6 7')
print(m)
from numpy import *
m=matrix('1 2 ; 3 6 ; 4 5 ; 6 7')
print(m)
#to print diagonal elements
from numpy import *
m=matrix('1 2 3 ; 6 4 5 ; 1 6 7')
print(diagonal(m))
from numpy import *
m=matrix('1 2 ; 3 6 ; 4 5 ; 6 7')
print(m.min())
print(m.max())
from numpy import *
m1=matrix('1 2 3 ; 6 4 5 ; 1 6 7')
m2=matrix('1 2 3 ; 6 8 5 ; 2 6 7')
m3=m1 + m2
print(m3)
m3=m1 * m2
print(m3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16121495327102803, 'fraction_numerical': 0.07584471603163193, 'mean_word_length': 5.062091503267974, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '386767', 'license': 'Apache-2.0', 'n_tokens_mistral': 2476, 'n_tokens_neox': 2313, 'n_words': 600, 'path': 'ARRAY.ipynb', 'repo_name': 'Naina-Kshatri/Python_Programs', 'size': '5564'}