[PYTHON] numpy part 1

ndarray n-dimensional array

1


import numpy as np

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

Execution result of 1


[[1 2 3]
 [4 5 6]]

You can specify the data type of the array. How many bits of type should be used? You can adjust the amount of memory to be secured by specifying the number of bits.

2


import numpy as np

a = [1, 2, 3]

ndarray = np.array(a, dtype='float32')
print(ndarray.dtype)

ndarray = np.array(a, dtype='int32')
print(ndarray.dtype)

Execution result of 2


float32
int16

Change data type

3


import numpy as np

a = [1, 2, 3]

arr = np.array(a, dtype='int32')
arr2 = arr.astype('float32')

print(arr2.dtype)

Execution result of 2


float32

Recommended Posts

numpy part 1
numpy part 2
datetime part 1
numpy practice 1
Numpy [Basic]
NumPy basics
argparse part 1
Numpy Memorandum_Matrix
numpy tips
Multidimensional array calculation without Numpy Part 2
About numpy
Python application: Numpy Part 3: Double array
NumPy axis
Use Numpy
Queuing theory part 4
neo4j sandbox part 12
My Numpy (Python)
QGIS + Python Part 2
neo4j sandbox part 5
where in numpy
Django begins part 1
Manim's method part 23
Report_Deep Learning (Part 2)
Report_Deep Learning (Part 1)
Report_Deep Learning (Part 1)
QGIS + Python Part 1
GMT installation part 2.
GMT installation part 1.
Django begins part 4
numpy unit test
NumPy array manipulation (3)
Report_Deep Learning (Part 2)
list and numpy
neo4j sandbox part 13
NumPy universal functions
neo4j sandbox part 15
numpy memorandum 1 / np.pad
Queuing theory part 3
#Python basics (#Numpy 1/2)
#Python basics (#Numpy 2/2)
numpy index search
Python: Scraping Part 1
NumPy array manipulation (1)
neo4j sandbox part 16
[Numpy] Shuffle ndarray
Python #Numpy basics
numpy non-basic techniques
About Numpy broadcast
[PyTorch] Sample ① ~ NUMPY ~
neo4j sandbox part 11
Install Numpy + atlas
Python3 Beginning Part 1
[Python] Numpy memo
Python: Scraping Part 2
pandas series part 1
Introduction to Python numpy pandas matplotlib (~ towards B3 ~ part2)