Skip to main content
Commonmark migration
Source Link

#Python 2 + NumPy, 122 bytes

Python 2 + NumPy, 122 bytes

I admit it. I worked ahead. Unfortunately, this same method cannot be easily modified to solve the other 2 related challenges...

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

###Explanation:

Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the anti-diagonals of the matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 

#Python 2 + NumPy, 122 bytes

I admit it. I worked ahead. Unfortunately, this same method cannot be easily modified to solve the other 2 related challenges...

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

###Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the anti-diagonals of the matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 

Python 2 + NumPy, 122 bytes

I admit it. I worked ahead. Unfortunately, this same method cannot be easily modified to solve the other 2 related challenges...

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the anti-diagonals of the matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 
added 101 characters in body
Source Link
mbomb007
  • 23.6k
  • 7
  • 66
  • 143

#Python 2 + NumPy, 122 bytes

I admit it. I worked ahead. Unfortunately, this same method cannot be easily modified to solve the other 2 related challenges...

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

###Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the anti-diagonals of the matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 

#Python 2 + NumPy, 122 bytes

I admit it. I worked ahead.

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

###Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the anti-diagonals of the matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 

#Python 2 + NumPy, 122 bytes

I admit it. I worked ahead. Unfortunately, this same method cannot be easily modified to solve the other 2 related challenges...

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

###Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the anti-diagonals of the matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 
deleted 4 characters in body
Source Link
mbomb007
  • 23.6k
  • 7
  • 66
  • 143

#Python 2 + NumPy, 122 bytes

I admit it. I worked ahead.

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

###Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the anti-diagonals of the reversed matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 

#Python 2 + NumPy, 122 bytes

I admit it. I worked ahead.

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

###Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the diagonals of the reversed matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 

#Python 2 + NumPy, 122 bytes

I admit it. I worked ahead.

import numpy def f(m):w=len(m);print sum([list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))],[]) 

Takes a numpy array as input. Outputs a list.

Try it online

###Explanation:

def f(m): w=len(m) # the height of the matrix, (at one point I thought it was the width) # get the anti-diagonals of the matrix. Reverse them if odd by mapping odd to -1 d=[list(m[::-1,:].diagonal(i)[::(i+w+1)%2*-2+1])for i in range(-w,w+len(m[0]))] # w+len(m[0]) accounts for the width of the matrix. Works if it's too large. print sum(d,[]) # join the lists 

A lambda is the same length:

import numpy lambda m:sum([list(m[::-1,:].diagonal(i)[::(i+len(m)+1)%2*-2+1])for i in range(-len(m),len(m)+len(m[0]))],[]) 
added 384 characters in body
Source Link
mbomb007
  • 23.6k
  • 7
  • 66
  • 143
Loading
Source Link
mbomb007
  • 23.6k
  • 7
  • 66
  • 143
Loading