Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

matrix diagonal sum Python

# Problem Link : https://leetcode.com/problems/matrix-diagonal-sum/

class Solution(object):
    def diagonalSum(self, array):
        """
        :type array: List[List[int]]
        :rtype: int
        """
        n = len(array)
        primary = 0
        secondary = 0;
        for i in range(0, n):
            primary += array[i][i]
            secondary += array[i][n-i-1]
        if (n % 2 == 0): return primary + secondary
        else: return primary + secondary - array[n//2][n//2]
Comment

how to sum numpy matrix diagonal

np.trace(matrix)
Comment

sum of diagonal numpy


arr= np.arange(16)
arr= np.reshape(arr,(4,4))

a=np.diagonal(arr, 0,0,1)

result=sum(a)
print(result)
Comment

matrix diagonal sum Python

# Problem Link : https://leetcode.com/problems/matrix-diagonal-sum/

class Solution(object):
    def diagonalSum(self, array):
        """
        :type array: List[List[int]]
        :rtype: int
        """
        n = len(array)
        primary = 0
        secondary = 0;
        for i in range(0, n):
            primary += array[i][i]
            secondary += array[i][n-i-1]
        if (n % 2 == 0): return primary + secondary
        else: return primary + secondary - array[n//2][n//2]
Comment

how to sum numpy matrix diagonal

np.trace(matrix)
Comment

sum of diagonal numpy


arr= np.arange(16)
arr= np.reshape(arr,(4,4))

a=np.diagonal(arr, 0,0,1)

result=sum(a)
print(result)
Comment

PREVIOUS NEXT
Code Example
Python :: how to get only the string of the input not the spaces arournd it in python 
Python :: Python loop aray 
Python :: install open3d jetson nano aarch64 
Python :: twitter api ("Connection broken: Invalid Chunk Length(got length b', 0 bytes read)" 
Python :: salamelecus 
Python :: python sleep for 1 minute 
Python :: element wise mean and std 
Python :: dic to dic arrays must all be same length 
Python :: python message from byte 
Python :: unable to access jupiter assertions 
Python :: How to play audio in background 
Python :: biodiversity 
Python :: gun in python turtle 
Python :: gensim wordvector vocabulary list 
Python :: print a commans in python 
Python :: qcombobox remove all items 
Python :: Pandas: Filter column value in array/list - ValueError: The truth value of a Series is ambiguous 
Python :: turtle meaning 
Python :: disable json dumps encode 
Python :: 1038 solution python 
Python :: advanced use of tuples in python 
Python :: Code converter C++ to python 
Python :: open pdf from pyqt in the same folder 
Python :: Univariant Variable Analysis - Multiple Plots 
Python :: A Simple Class 
Python :: Iterate over several iterables in parallel 
Python :: Count the number of Non-Missing Values in the DataFrame 
Python :: python module equal override 
Python :: Calculate summary statistics across columns 
Python :: An error occurred while connecting: 10049: The requested address is not valid in its context.. scrapy splash 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =