Categories
Mastering Development

Performing prime value pairs in python

I am currently stuck on Project Euler problem 60. The problem goes like this: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The sum […]

Categories
Mastering Development

Conversion of nested list to np.array for tensor model prediction is incorrect

I have an input array created from : initial window = ‘I have a bad feeling about this’ seq_tokens = t.texts_to_sequences(initial_window) # seq_tokens = [[4], [], [], [5], [590], [], [], [5], [], [998], [5], [], [], [], [], [], [], [4], [], [], [], [5], [998], [591], [], [], [], [], [], [4], []] […]

Categories
Mastering Development

indexing rows and columns in numpy

a = np.array(list(range(16).reshape((4,4)) array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) Say I want the middle square. It’d seem reasonable to do this: a[[1,2],[1,2]] but I get this: array([5, 10]) This works, but seems inelegant: a[[1,2],:][:,[1,2]] array([[5, 6], [9, 10]]) So my questions are: […]

Categories
Mastering Development

How do you create a long number from a List

How do you create a long number from a List<Integer> ? From: List<Integer> ints = Arrays.asList(1,2,3,4,5,6,7,8,9) TO: long = 1234567489 Thanks

Categories
Mastering Development

How to add limited hints when programming a quiz?

I am making a trivia quiz that allows users to solve 10 trivia questions and get a score. I am planning to provide the users 3 hints and print out Sorry! You used all the hints. when the user uses all 3 hints. How do I do that? I know I would need to use […]

Categories
Mastering Development

Syntax Error: ‘return’ outside function: my indentations seem to be correct

So first of all im writing a program that will total up all of the values in a list / array and heres what i got so far def go( ann ): total = 0 for i in range(0,len(ann)): total = total+ann[i] return total print ( go( [-99,1,2,3,4,5,6,7,8,9,10,12345] ) ) print ( go( [10,9,8,7,6,5,4,3,2,1,-99] ) […]

Categories
Mastering Development

Alternative to IF Statement for deletion

I have the following script running in a SSIS Execute SQL Task which is taking exceptionally long to execute : DECLARE @Year int DECLARE @Month int SET @Year = YEAR(GETDATE()) SET @Month = MONTH(GETDATE()) IF @Month IN (1,2,3,4,5,6,7,8,9) BEGIN SET @Year = @Year-1 DELETE FROM GLYTDMovement WHERE CGYear >= @Year AND Entity NOT LIKE ‘TT%’ […]

Categories
Mastering Development

How to get key from the value of dictionary

I have the following set of rules for grading system if 25 < score <= 30, grade = A. if 20 < score <= 25, grade = B. if 15 < score <= 20, grade = C. if 10 < score <= 15, grade = D. if 5 < score <= 10, grade = E. […]

Categories
Mastering Development

Pandas correlation maxtrix between float columns and string columns

How can I get a correlation matrix in Pandas between float columns and string columns? Using df.corr() automatically drops the string columns. I tried pd.get_dummies(), but this "widens" the dataframe and returns 1/0 in the widened columns. The purpose is to plot a heatmap of the correlation. Of course ‘dog’ and ‘dog’ will have a […]

Categories
Mastering Development

Get/extract factorisation from SparseOpaqueFactorization using Accelerate

I am writing some Linear Algebra algorithms using Apples Swift / Accelerate framework. All works and the solved Ax = b equations produce the right results (this code is from the apple examples). I would like to be able to extract the LLT factorisation from the SparseOpaqueFactorization_Double object. But there doesn’t seem to be any […]