![]() Self.args = įile "/home/michael/opt/miniconda3/envs/roomassignments/lib/python3.7/site-packages/cvxpy/atoms/atom.py", line 49, in įile "/home/michael/opt/miniconda3/envs/roomassignments/lib/python3.7/site-packages/cvxpy/expressions/expression.py", line 472, in cast_to_const Super(Sum, self)._init_(expr, axis=axis, keepdims=keepdims)įile "/home/michael/opt/miniconda3/envs/roomassignments/lib/python3.7/site-packages/cvxpy/atoms/axis_atom.py", line 36, in _init_įile "/home/michael/opt/miniconda3/envs/roomassignments/lib/python3.7/site-packages/cvxpy/atoms/atom.py", line 49, in _init_ The above exception was the direct cause of the following exception:įile "/home/michael/opt/miniconda3/envs/roomassignments/lib/python3.7/site-packages/cvxpy/atoms/affine/sum.py", line 114, in sumįile "/home/michael/opt/miniconda3/envs/roomassignments/lib/python3.7/site-packages/cvxpy/atoms/affine/sum.py", line 43, in _init_ TypeError: float() argument must be a string or a number, not 'Variable' Type "help", "copyright", "credits" or "license" for more information. The Footer in the TIO link converts the inputs into 2D arrays, runs the above link over them then outputs them similar to the input format. I know there's already 2 Jelly answers, but this, I think, is fairly different from them both, and is shorter. U Reverse each row, so that consecutive calls fix the other corners. ŒḌ Convert the diagonals back to the matrix. Ñ Call the first helper link on the diagonal to pad it with its sum. Ṗ Remove the last item (incorrect bottom corner). Ḋ Remove the first item (incorrect top corner). ![]() and keep the result for the first item (main diagonal): Μ€ Perform the following actions on each diagonal.ġ¦. ŒD Get the diagonals of the matrix, starting with the main diagonal. ÑÑ Call the second helper link twice on the whole matrix. ⁺ Repeat the previous chain (everything up to here). Z Transpose, so that the second invocation uses the columns. Ç Call the first helper link (pad row with sums). The first helper link pads a vector with its sum on both ends, the second helper link fixes two corners of the matrix and the main link calls these appropriately. Too bad it requires a € to work with Ç in my case. I finally managed to understand how ¦ works (by debugging through Jelly's code, lol). Looks surprisingly different from Erik's solution. P % Flip vertically again, to restore initial orientation % the verticallly flipped version of the result matrix % this gives the sum of the anti-diagonal of the input.ĥL( % Write that into the upper-left and lower-right corners of Since the input has been vertically flipped, GP % Push input matrix vertically flipped % matrix that is, its upper-left and lower-right corners Sum of vectorĥL( % Write that into first and last entries of the result matrix Xds % Column vector with the diagonal of the matrix. % the matrix with the correct orientation (transposed twice) % each row (first iteration) and column (second), leaving Wy % Push a copy to the bottom of the stack Xs % Row vector with the sum of each column Takes input implititly in the first iteration ![]() MATL, 27 26 bytes ,!tXswyv]GXds5L(PGPXds5L(P This is code-golf, so the shortest solution in each language wins. Use the submissions in this challenge if you want to convert the input format to a more suitable one (for instance ,]). Optional format, but it must be the same as the input format.A non-empty square matrix, with non-negative integers.The top right and bottom left elements are the sum of the anti-diagonal \$2 2 3=7\$. The top left and bottom right elements are the sum of the diagonal \$1 2 5=8\$. ![]()
0 Comments
Leave a Reply. |