Use tolist()
:
import numpy as np >>> np.array([[1,2,3],[4,5,6]]).tolist() [[1, 2, 3], [4, 5, 6]]
Note that this converts the values from whatever numpy type they may have (e.g. np.int32 or np.float32) to the “nearest compatible Python type” (in a list). If you want to preserve the numpy data types, you could call list() on your array instead, and you’ll end up with a list of numpy scalars. (Thanks to Mr_and_Mrs_D for pointing that out in a comment.)
Related Posts:
- numpy array: IndexError: too many indices for array
- Python3 – ModuleNotFoundError: No module named ‘numpy’
- ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
- Curve curvature in numpy
- How can I prevent the TypeError: list indices must be integers, not tuple when copying a python list to a numpy array?
- The difference between comparison to np.nan and isnull()
- ‘numpy.ndarray’ object has no attribute ‘index’
- How to update/upgrade a package using pip?
- How do I update\upgrade pip itself from inside my virtual environment?
- IndexError: too many indices for array
- How do I specify new lines on Python, when writing on files?
- bash: pip: command not found
- How do I check what version of Python is running my script?
- Converting integer to string in Python
- Reverse a string in Python
- Python for-in loop preceded by a variable
- Python Linked List
- What does if __name__ == “__main__”: do?
- How to print without a newline or space
- Error: ‘int’ object is not subscriptable – Python
- How to measure elapsed time in Python?
- How to uninstall Anaconda completely from macOS
- Python: Start and stop timer [duplicate]
- Does Python have a ternary conditional operator?
- not all arguments converted during string formatting.. NO % variables
- How do I install opencv using pip?
- TypeError: ‘builtin_function_or_method’ object is not subscriptable
- How do I compare two strings in python?
- numpy max vs amax vs maximum
- ImportError: No module named sklearn.cross_validation
- What are data classes and how are they different from common classes?
- Tensorflow import error: No module named ‘tensorflow’
- Python random function
- ImportError: No module named matplotlib.pyplot
- How do you get the logical xor of two variables in Python?
- ValueError: could not convert string to float: id
- Pip freeze vs. pip list
- Difference between import numpy and import numpy as np
- why numpy.ndarray is object is not callable in my simple for python loop
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- How do I create an empty array/matrix in NumPy?
- Converting list to numpy array
- How do I read CSV data into a record array in NumPy?
- How to normalize a NumPy array to a unit vector?
- ImportError: numpy.core.multiarray failed to import
- ImportError: numpy.core.multiarray failed to import
- size of NumPy array
- Syntax in Python (.T)
- Convert a tensor to numpy array in Tensorflow?
- Use a.any() or a.all()
- ‘DataFrame’ object has no attribute ‘sort’
- convert nan value to zero
- Most efficient way to map function over numpy array
- Is there a NumPy function to return the first index of something in an array?
- initialize a numpy array
- TypeError: ‘DataFrame’ object is not callable
- Cannot convert list to array: ValueError: only one element tensors can be converted to Python scalars
- How can I use numpy.correlate to do autocorrelation?
- Calculating Covariance with Python and Numpy
- Dump a NumPy array into a csv file
- Inverse of a matrix using numpy
- Python: slicing a multi-dimensional array
- How to implement the Softmax function in Python
- 3-dimensional array in numpy
- How do you get the magnitude of a vector in Numpy?
- ‘list’ object has no attribute ‘shape’
- What is the difference between np.mean and tf.reduce_mean?
- How to calculate rolling / moving average using python + NumPy / SciPy?
- ValueError: object too deep for desired array while using convolution
- Make list of arrays in python
- Import Error: No module named numpy Anaconda
- What does ‘index 0 is out of bounds for axis 0 with size 0’ mean?
- pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
- Moving average or running mean
- ValueError: x and y must be the same size
- How to fix “TypeError: len() of unsized object”
- NumPy List Comprehension Syntax
- Linear regression with matplotlib / numpy
- How to get the unit vector from a numpy array
- Numpy float64 vs Python float
- RuntimeError: module compiled against API version a but this version of numpy is 9
- urllib2.HTTPError: HTTP Error 403: Forbidden
- TypeError: ‘numpy.float64’ object does not support item assignment
- Python/Django: log to console under runserver, log to file under Apache
- numpy-equivalent of list.pop?
- Efficiently sorting a numpy array in descending order?
- How to add column to numpy array
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- IndexError: index 2 is out of bounds for axis 0 with size 2
- Coalesce values from 2 columns into a single column in a pandas dataframe
- Compute a confidence interval from sample data
- How do I compute derivative using Numpy?
- ImportError: cannot import name NUMPY_MKL
- built-in range or numpy.arange: which is more efficient?
- Convert a 1D array to a 2D array in numpy
- inverting image in Python with OpenCV
- How to print the full NumPy array, without truncation?
- TypeError: zip argument #2 must support iteration
- CS231n: How to calculate gradient for Softmax loss function?
- Numpy matrix to array