Home  >  Article  >  Backend Development  >  How to increase matrix dimension in python

How to increase matrix dimension in python

php中世界最好的语言
php中世界最好的语言Original
2018-04-09 17:22:144433browse

This time I will bring you pythonHow to increase the matrix dimension, what are the precautions for increasing the matrix dimension in Python, the following is a practical case, let's take a look.

numpy.expand_dims(a, axis)

Examples

>>> x = np.array([1,2])
>>> x.shape
(2,)
>>> y = np.expand_dims(x, axis=0)
>>> y
array([[1, 2]])
>>> y.shape
(1, 2)
>>> y = np.expand_dims(x, axis=1) # Equivalent to x[:,newaxis]
>>> y
array([[1],
    [2]])
>>> y.shape
(2, 1)

I believe you read this article You have mastered the case method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Operation excel to read and write data

##How to perform automated unit testing with Python Unittest

The above is the detailed content of How to increase matrix dimension in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn