Getting tle error

i have used the prime sieve to reduce the time complexity but still getting TLE in testcase 2.

Hey,
Instead of calling soe for different test cases again.
Make one array with max size (according to constraints) make mark all prime numbers there just for 1 time…
And in test cases just print that array numbers in range (a,b) . This way you don’t need to create prime numbers array for different test cases.

Thanks :slight_smile:

1 Like

one more this in logistic regression we just did
grad=np.dot(X.T, (Y_-Y))
without creating the grad vector like we did earlier grad=np.zeroes((2,))
.

Both ways are fine.
Instead of initializing grad with zeros we directly set the required values…

please elaborate a bit. what i am confused wid is i am thinking that when we dont initialize grad and doing np. dot it means there is only one value of grad unlike grad[0] and grad[1]… the thing i am not exactly able to write and tell my problem. so please elaborate both the cases. Thanks in advance

Suppose X has the shape (100,2) so, X.T has shape (2,100)
Y has shape (100,1) Y_ also has shape (100,1)
(Y_ - Y ) again shape is same (100,1)

now mutiply (2,100) * (100, 1) it will form a vector of (2,1) which is same shape as when we did np.zeros((2,)) for grads.

The result of grad=np.dot(X.T, (Y_-Y)) will fetch you a grad vector with 2 dimn.

so now if i do grad[0] it will give first gradient value, and grad[1] will give you second grad.
So rather than calculating gradients differently for diferent grads we used vectorization to compute all grads in just one line of code. Suppose, If you get lots of grads say 20 you can’t do that manually for each grad.

I hope this helps now :slight_smile:

1 Like

got it thanks a lot for the help

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.