Create a python numpy array

Let's make an array of numpy

One-dimensional array

>>> import numpy as np
>>> my_array1 = np.array([1,2,3,4])
>>> my_array1
array([1, 2, 3, 4])

One-dimensional array-conversion from list (same as ↑)

>>> my_list1 = [1,2,3,4]
>>> my_array1 = np.array(my_list1)
>>> my_array1
array([1, 2, 3, 4])

Two-dimensional array

>>> my_lists = [my_list1,[11,22,33,44]]
>>> my_array2 = np.array(my_lists)
>>> my_array2
array([[ 1,  2,  3,  4],
       [11, 22, 33, 44]])

Check the size of the array

>>> my_array2.shape
(2, 4)

Examine the data type of the array

>>> my_array2.dtype
dtype('int64')

Make various arrays (zero, one, empty, identity matrix, arrange)

>>> np.zeros(5)
array([ 0.,  0.,  0.,  0.,  0.])

>>> np.ones((5,5))
array([[ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.]])

>>> np.empty(5)
array([  0.00000000e+000,   7.84296818e-315,   4.94065646e-324,
                     nan,   1.02378882e-311])

>>> np.eye(5)
array([[ 1.,  0.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  1.]])

>>> np.arange(5)
array([0, 1, 2, 3, 4])

Recommended Posts

Create a python numpy array
python numpy array calculation
Create a Python environment
Create a C array from a Python> Excel sheet
Create a Wox plugin (Python)
Create a function in Python
Create a dictionary in Python
Create a directory with python
[Python] Create structured array (store heterogeneous data with NumPy)
[python] Create a date array with arbitrary increments with np.arange
Subscript access to python numpy array
Create a python GUI using tkinter
Create a DI Container in Python
Create a Python environment on Mac (2017/4)
Create a virtual environment with Python!
Create a binary file in Python
Create a python environment on centos
Python application: Numpy Part 3: Double array
Create a Python general-purpose decorator framework
Create a Kubernetes Operator in Python
5 Ways to Create a Python Chatbot
Create a random string in Python
Let's create a PRML diagram with Python, Numpy and matplotlib.
Create a new Python numerical calculation project
Create a dummy image with Python + PIL.
Create a python environment on your Mac
Python multidimensional array
Let's create a virtual environment for Python
[Beginner] Python array
Python / numpy> list (numpy array) file save / load
Create a JSON object mapper in Python
NumPy array manipulation (3)
[Python] [LINE Bot] Create a parrot return LINE Bot
#Python basics (#Numpy 1/2)
#Python basics (#Numpy 2/2)
What I did with a Python array
Create a word frequency counter with Python 3.4
Create a deb file from a python package
NumPy array manipulation (1)
[Python] Create a LineBot that runs regularly
[GPS] Create a kml file in Python
Python array basics
Python #Numpy basics
[Python] Numpy memo
How to sort by specifying a column in the Python Numpy array.
Create a frame with transparent background with tkinter [Python]
[Python] List Comprehension Various ways to create a list
Edit Excel from Python to create a PivotTable
Create a Vim + Python test environment in 1 minute
Create a GIF file using Pillow in Python
[Python] Road to a snake charmer (4) Tweak Numpy
[python] Create a list of various character types
Create a LINE BOT with Minette for Python
I want to create a window in Python
Create a standard normal distribution graph in Python
How to create a JSON file in Python
Create a virtual environment with conda in Python
Create a page that loads infinitely with python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a web map using Python and GDAL