Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
1 answer
140 views

Returning all divisors of a number as a matrix with N X 2 dimensions

I have developed a class structure with methods to return a matrix from a single input array. The objective is to insert the middle value of the array so 2n remains ...
Dollar X's user avatar
2 votes
2 answers
800 views

Finding distance between vectors of matrices

So here is the problem: Given 2D numpy arrays 'a' and 'b' of sizes n×m and k×m respectively and one natural number 'p'. You need to find the distance(Euclidean) of the rows of the matrices 'a' and ...
Levon Avetisyan's user avatar
7 votes
1 answer
214 views

Computing sums of weird pattern in 2D array as efficiently as possible

This is a problem from Hackerrank (https://www.hackerrank.com/challenges/2d-array/problem). We're given a 6x6 (always) 2D array and asked to compute the sums of all the hourglass patterns in the array....
jeremy radcliff's user avatar
3 votes
1 answer
54 views

How to optimize code to take advantage of NumPy broadcasting when calculating pairwise correlation?

I'm trying to take advantage of NumPy broadcasting and backend array computations to significantly speed up this function. Unfortunately, it doesn't scale so well so I'm hoping to greatly improve the ...
O.rka's user avatar
  • 201
2 votes
1 answer
2k views

Rotate matrix 90 degrees

I recently did problem 1.7 Rotate Matrix in Cracking the Coding Interview. I realized my code is very different than what is in the book and also from what I'm finding online (I'm having trouble ...
stillearning's user avatar
5 votes
1 answer
2k views

Extending numpy array by replacing each element with a matrix

Suppose I have a H*W numpy array like this (H=3 and W=2): ...
Delgan's user avatar
  • 621
5 votes
1 answer
1k views

Improving the manipulation of 2D Arrays for an easy challenge on HackerRank with Python 3

I am practicing some exercises on HackerRank in order to improve my skills on Python3. I am doing the 30 days challenge. There is one challenge involving matrices. I was able to pass the test cases ...
user avatar
0 votes
2 answers
2k views

Effective Python 2/3 two-dimensional array initialisation

Recently I noticed that the idiomatic python two-dimensional array initialisation is extremely slow. I am wondering, is there a good, proper way of doing this simple task fast? Also, are those two ...
vegi's user avatar
  • 201