Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

transpose matrix numpy

>>> a = np.array([[1, 2], [3, 4]])
>>> a
array([[1, 2],
       [3, 4]])
>>> a.transpose()
array([[1, 3],
       [2, 4]])
>>> a.transpose((1, 0))
array([[1, 3],
       [2, 4]])
>>> a.transpose(1, 0)
array([[1, 3],
       [2, 4]])
Comment

transpose matrices numpy

import numpy as np

A = [1, 2, 3, 4]
np.array(A).T # .T is used to transpose matrix
Comment

transpose matrix in python without numpy

def transpose(matrix):
    rows = len(matrix)
    columns = len(matrix[0])

    matrix_T = []
    for j in range(columns):
        row = []
        for i in range(rows):
           row.append(matrix[i][j])
        matrix_T.append(row)

    return matrix_T
  
Comment

numpy transpose

>>> np.transpose(x)
array([[0, 2],
       [1, 3]])
Comment

numpy transpose

ndarray.T

x = np.array([[1.,2.],[3.,4.]])
>>> x
array([[ 1.,  2.],
       [ 3.,  4.]])
>>> x.T
array([[ 1.,  3.],
       [ 2.,  4.]])
>>> x = np.array([1.,2.,3.,4.])
>>> x
array([ 1.,  2.,  3.,  4.])
>>> x.T
array([ 1.,  2.,  3.,  4.])
Comment

transpose matrice numpy

>>> np.transpose(M)
array([[1, 4, 7],
       [2, 5, 8],
       [3, 6, 9]])
Comment

transpose of a matrix in python numpy

np.transpose(x)
array([[0, 2],
       [1, 3]])
Comment

transpose matrice numpy

>>> import numpy as np
>>> M = np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> M
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])
>>> M.T
array([[1, 4, 7],
       [2, 5, 8],
       [3, 6, 9]])
Comment

transpose of a matrix using numpy

M = np.matrix([[1,2],[3,4]])

M.transpose()
Comment

PREVIOUS NEXT
Code Example
Python :: typing pandas dataframe 
Python :: for pyton 
Python :: insert list python 
Python :: python get first letter of string 
Python :: reverse function python 
Python :: python list of whole numbers 
Python :: python find string in list 
Python :: convert all numbers in list to string python 
Python :: py2exe no console 
Python :: array of objects in python 
Python :: how to compare values in dictionary with same key python 
Python :: python opérateur ternaire 
Python :: how to end an infinite loop in specific time python 
Python :: install apriori package python 
Python :: dataframe pandas empty 
Python :: python contextmanager 
Python :: python pass 
Python :: python regex search a words among list 
Python :: if string in list python 
Python :: how to plot in python 
Python :: save bool using playerprefs 
Python :: weighted average in python pandas 
Python :: conda enviroment python version 
Python :: get filename from path python 
Python :: python bufferedreader 
Python :: if else python 
Python :: make password python 
Python :: python sort multiple keys 
Python :: python make 1d array from n-d array 
Python :: formate a phonenumber in phonenumber package with phonenumberformat 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =