# Tag: math

## Rotate a line by a specific angle

I have a line with lenght of l and p1 and p2 and i want to rotate it by angle. I was using this matrix but it doesn’t work. matrix I have this code in python: Answer You first need to specify an origin point, the rotation will be created around that point. You can adapt your code and use

## how to calculate the distances between all datapoints among each other

I want to check which data points within X are close to each other and which are far. by calculating the distances between each other without getting to zero, is it possible? Answer Using just numpy you can either do, or,

## Geometric series: calculate quotient and number of elements from sum and first & last element

Creating evenly spaced numbers on a log scale (a geometric progression) can easily be done for a given base and number of elements if the starting and final values of the sequence are known, e.g., with numpy.logspace and numpy.geomspace. Now assume I want to define the geometric progression the other way around, i.e., based on the properties of the resulting

## Floating-point errors in cube root of exact cubic input

I found myself needing to compute the “integer cube root”, meaning the cube root of an integer, rounded down to the nearest integer. In Python, we could use the NumPy floating-point cbrt() function: Though this works most of the time, it fails at certain input x, with the result being one less than expected. For example, icbrt(15**3) == 14, which

## Is there a more elegant way of counting combinations of booleans from 2 arrays?

I tried to word the question as simply as possible but I’m new to Python and very bad at logic so I’m having a bit of trouble. Basically I want to know if there’s a cleaner way to count confusion matrices of two 1D arrays of booleans. Here’s an example: I tried this but it just adds more lines and

## JAX: Getting rid of zero-gradient

Is there a way how to modify this function (MyFunc) so that it gives the same result, but its derivative is not zero gradient? EDIT: Similar function which doesn’t give zero gradient – but it doesn’t return 30/20/10 Answer The gradient of your function is zero because this is the correct result for the gradient as your function is defined.

## Why is a hg.Vec3() vector passed to a Python function modified by it?

I’m working on a 3D project in Python using the HARFANG 3D wheel (I got from Pypi). I have a function where I pass a series of data, including a vector3: I don’t return position and it is not a global variable. However, when returning from this function, position is modified within the scope of the caller. How to I

## how to detect a braking process in python dataframe

I have some trips, and for each trip contains different steps, the data frame looks like following: I want to know if, on a trip X, the cyclist has braked (speed has decreased by at least 30%). The problem is that the duration between every two steps is each time different. For example, in 6 seconds, the speed of a

## python – weird results with exponent operator in idle

I’m getting a strange result when squaring -1 in idle. What’s going on? Unexpected result: Expected result: Answer Operator precedence (the – is a unary minus operator):

## Subtract specific value from a list (of numbers) by user input

I’m a begginer in Python and i’m trying to do a program when the user chooses a number from a list, then after you type by how you much want to reduce this chosed number and then print the list. I know that using list[specific index], check if matches with user input and repeating over and over again would do