Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

converting 1d array into upper triangular

In [680]: ind = np.triu_indices(4)
In [681]: values = np.arange(16).reshape(4,4)[ind]
In [682]: result = np.zeros((4,4),int)
In [683]: result[ind]=values
In [684]: values
Out[684]: array([ 0,  1,  2,  3,  5,  6,  7, 10, 11, 15])
In [685]: result
Out[685]: 
array([[ 0,  1,  2,  3],
       [ 0,  5,  6,  7],
       [ 0,  0, 10, 11],
       [ 0,  0,  0, 15]])
Comment

PREVIOUS NEXT
Code Example
Python :: calendar range 
Python :: Use of Pass 
Python :: np random choice given distribution 
Python :: <function chr(i, /)> error in python 
Python :: python 2.0 
Python :: How to download images from the OIDv4 in Anaconda Promt 
Python :: Assigning X and y using .iloc index 
Python :: python scrapy 
Python :: round to nearest multiple of 5 python from both end 
Python :: Image loader RGB transform 
Python :: repalce na with mean per group 
Python :: convert month weeks days into month days in python pandas 
Python :: comment arrĂȘter un jeu en appuyant sur une touche python 
Python :: how to get a mouse press not hold in pygame 
Python :: can i register a list in python for input 
Python :: make image to string to use in tkinter 
Python :: Rewrite the equation shown in Figure 2.4 as a Python expression and get the result of the equation: Pay special attention to the order of operations. 
Python :: what is comma in regex 
Python :: divide column in each row by last column 
Python :: python program to check fibonacci number using functions 
Python :: indentation error in python atom editor 
Python :: NPAPI 
Python :: mongoengine ObjectIdField 
Python :: python interseciton of 2 sets 
Python :: how to code discord bot 8ball python 
Python :: Notice there is a bug when using astimezone() on utc time. This gives an incorrect result: 
Python :: np v stack 
Python :: space separated dictionary input in python 
Python :: sliding window maximum 
Python :: Count the data points based on columns 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =