-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumpy3.py
42 lines (34 loc) · 853 Bytes
/
numpy3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'''
Below is a list of all data types in NumPy and the characters used to represent them.
i - integer
b - boolean
u - unsigned integer
f - float
c - complex float
m - timedelta
M - datetime
O - object
S - string
U - unicode string
V - fixed chunk of memory for other type ( void )
'''
import numpy as np
arr = np.array(['apple', 'banana', 'cherry'])
print(arr.dtype)
arr = np.array([1, 2, 3, 4], dtype='S')
print(arr)
print(arr.dtype)
#Create an array with data type string
arr = np.array([1, 2, 3, 4], dtype='i4')
print(arr)
print(arr.dtype)
#Create an array with data type 4 bytes integer
#Converting Data Type on Existing Arrays
arr = np.array([1.1, 2.1, 3.1])
newarr = arr.astype('i') #you can use int inside the bracket
print(newarr)
print(newarr.dtype)
arr = np.array([1, 0, 3])
newarr = arr.astype(bool)
print(newarr)
print(newarr.dtype)