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.

Files for diagonal, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size diagonal-0.0.2-py3-none-any.whl (3.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size diagonal-0.0.2.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page