[python] -1 meaning of numpy's reshape method

numpy's reshape is a method that transforms a multidimensional array by specifying a numerical value, but if you use -1, you only need to specify one numerical value and the method will automatically do not specify the other numerical value. Will decide the numerical value.

An example of making a list of 3 elements into a 1-by-3 matrix


arr = [1,2,3]
print(len(arr))
# 3

narr1 = np.array(arr).reshape(1,3) 
print(narr1.shape)
# (1, 3)

narr2 = np.array(arr).reshape(1,-1)
print(narr2.shape)
# (1, 3)

Recommended Posts

[python] -1 meaning of numpy's reshape method
Intuitively learn the reshape of Python np
Meaning of using DI framework in Python
Introduction of Python
Clustering of clustering method
Basics of Python ①
Basics of python ①
Copy of python
Johnson method (python)
[Python] Semi-Lagrange method
Introduction of Python
[Python] Operation of enumerate
List of python modules
parallelization of class method
Unification of Python environment
Copy of python preferences
The meaning of self
Kernel Method with Python
Basics of Python scraping basics
Destroy the intermediate expression of the sweep method with Python
the zen of Python
Meaning of Linux permissions
Installation of Python 3.3 rc1
Simplex method (simplex method) in Python
[Python] Summary of table creation method using DataFrame (pandas)
Private method in python
# 4 [python] Basics of functions
Basic knowledge of Python
Sober trivia of python3
Summary of Python arguments
Basics of python: Output
Installation of matplotlib (Python 3.3.2)
Application of Python 3 vars
Summary of test method
Various processing of Python
A simple Python implementation of the k-nearest neighbor method (k-NN)
Different from the import type of python. from A import B meaning
[Python] Correct usage of map
Towards the retirement of Python2
Summary of python file operations
Summary of Python3 list operations
Python --Quick start of logging
Recommendation of binpacking library of python
[python] Value of function object (?)
[Python] Calculation method with numpy
Automatic update of Python module
Python --Check type of values
[Python] Etymology of python function names
About the ease of Python
Static analysis of Python programs
About various encodings of Python 3
Introduction of activities applying Python
python> Handling of 2D arrays
Version upgrade of python Anaconda
Handling of python on mac
python: Basics of using scikit-learn ①
2.x, 3.x character code of python
Comparison of 4 Python web frameworks
Simple FPS measurement of python
Check OpenSSL version of python 2.6
Python implementation of particle filters