Skip to main content

A small collection of functions to get various diagonals of a 2d matrix

Project description

A small module for getting diagonals in a 2D Array

import diagonal
arr = [] #your array


get(arr, start = "0", direction = "up", type="all")

start (single character)

0 - start from the first row

m - start from m'th row

direction (string)

up - uses upward direction for traversal

down - downward direction for traversal

**type **(string)

all - default value which indicates that all diagonals are considered

main - gives the main diagonal of square matrix

anti - gives anti diagonal of square matrix

zigzag - gives zigzag traversal of the matrix


  1. Square matrix

    • Main diagonal diagonal.get(arr, type = "main")

    • Anti diagonal diagonal.get(arr, type = "anti")

    • Also zigzags upwards and downwards

      diagonal.get(arr, type = "zigzag" ,direction ="up")

  2. Other matrices

    All traversals except main and anti diagonals

    Ex: diagonal.get(arr, start = "0", direction = "up") gives all diagonals starting from the first elements traversed in upward direction.

Return values

  • Any errors return a string

  • Main and Anti diagonal traversals returns a list

  • ZigZag traversals return a list

  • Others return a list of list having individual diagonals

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diagonal-0.0.2.tar.gz (2.4 kB view hashes)

Uploaded source

Built Distribution

diagonal-0.0.2-py3-none-any.whl (3.4 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page