0% found this document useful (0 votes)
4 views

Numpy

Uploaded by

netravathi1912
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Numpy

Uploaded by

netravathi1912
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

11/23/24, 11:19 AM Untitled0.

ipynb - Colab

import pandas

#harini k v
import numpy as np
#Creating an array:
a=np.array([42,69,55])
print(a)
print()
#Creating a 2_dimensional array:
p=np.array([[32,64,56],[44,86,45]])
print(p)
print()
#Printing the dimension:
print(a.ndim)
print(p.ndim)
print()
#Printing the data type;
print(p.dtype)
print()
#Defining the data type:
b=np.array([37.2,50.9,30.3],dtype="i")
b1=np.array([12,69,55],dtype="f")
print(b)
print(b1)
print(b.dtype)
print(b1.dtype)
print()
#Changing the datatype:
st=a.astype("S")
print(st)
print()
#Copying an array using copy():
a1=a.copy()
print("arrays after copying using copy()")
print(a)
print(a1)
a1[0]=21
print("Arrays after manipulating a1")
print(a)
print(a1)
print()
#Copying an array using view():
a2=a.view()
print("Arrays after copying using view()")
print(a)
print(a2)
print("Arrays after manipulating a2")
a2[0]=21
print(a)
print(a2)
print()
#reshaping the array:
w=np.array([1,2,3,4,5,6,7,8,9,10,11,12])
w1=w.reshape(4,3)
print(w1)
w2=w.reshape(2,3,2)
print(w2)
print()
#sorting the array:
np.sort(a)
np.sort(p)
print()
#Spliting of array:
arr=np.array_split(w,9)
print(arr)

[42 69 55]

[[32 64 56]
[44 86 45]]

1
2

int64

[37 50 30]
[12. 69. 55.]
int32
float32

https://colab.research.google.com/drive/1NynmS95v-bT9jgCZCtOZghhw7wf49SNw#scrollTo=LkhylUN9h-g4&printMode=true 1/2
11/23/24, 11:19 AM Untitled0.ipynb - Colab

[b'42' b'69' b'55']

arrays after copying using copy()


[42 69 55]
[42 69 55]
Arrays after manipulating a1
[42 69 55]
[21 69 55]

Arrays after copying using view()


[42 69 55]
[42 69 55]
Arrays after manipulating a2
[21 69 55]
[21 69 55]

[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
[[[ 1 2]
[ 3 4]
[ 5 6]]

[[ 7 8]
[ 9 10]
[11 12]]]

[array([1, 2]), array([3, 4]), array([5, 6]), array([7]), array([8]), array([9]), array([10]), array([11]), array([12])]

https://colab.research.google.com/drive/1NynmS95v-bT9jgCZCtOZghhw7wf49SNw#scrollTo=LkhylUN9h-g4&printMode=true 2/2

You might also like