In my attempt to dig deeper in the math behind machine learning models, I’m implementing a Ordinary Least Square algorithm in Python, using vectorization. My references are: https://github.com/paulaceccon/courses/blob/main/machine_learning_specialization/supervisioned_regression/2_multiple_regression.pdf https://www.geeksforgeeks.org/linear-regression-implementation-from-scratch-using-python/ This is what I have now: The problem I’m facing is that my weights keep increasing until I end up getting a bunch of nans. I’ve been trying to find out
Tag: numpy
Is there a way to wrap every single entry of an numpy.ndarray into a separate array?
I’m facing some problems getting an array into the right shape to use it as an input into a convolutional neural net: My array has the shape (100,64,64), but I’d need it to be (100,64,64,1). I realize it looks a bit odd, but I basically want to pack every single entry into a separate array. A simplified example, with a
Using a for loop to append to arrays in Numpy Python
The code below generates random integers within a given range within the for loop and I want to assign these values to the numpy arrays Values, up_value_one,up_value_two however the for loop below does not work. The Values of the Values, up_value_one,up_value_two are returned as empty arrays. How would I be able to use appender as the variable to append a,b,c
Setting item to numpy array with numba doesn’t execute and it doesn’t raise any exception
When I search for a solution of why the code below doesn’t run, I always conclude that it should just work. I am essentially trying to speed up the colouring of RGB images using numba. I get that the problem is with setting the item into the brushOverlay array because if I simply get the item and print it, it
How can I display dates on the x axis in matplotlib?
I have daily data from 1994 Jan 1st – 2000 April 30th. I have the dates in datetime format, but when I plot a line plot with time on the x axis and the variable on the y axis, matplotlib prints out way too much on the x axis. How do I fix this issue with plotting dates? I have
How to access items from ndarray with dtype=object
How can I access data inside a numpy array with dtype=object? The following raises an IndexError. Answer Since you passed in the dict to numpy.array() without putting it in a list, this is a zero-dimensional array. To index into a zero-dimensional array, you can use b.item() to access the element inside. For completeness, to access the data in the “a”
How to rasterize a batch of polygons in python
I have a batch of polygons which could be a NumPy array, torch tensor, or any other nd-array of shape (230_000, 3, 2). 230_000 is the number of polygons, 3 indicates it’s a triangle, 2 is its x and y coordinates. I also have a batch of features of shape (230_000, 3, 3) (last is the color), it’s best the
Count how often values in a 2D array appear in a 3D array
I have one 2-dimensional numpy array and another 3D-dimensional array. For each number in the first array I would like to count how often this value or an extremer one appears in the second array (taking the 3rd dimension as comparison vector for each element in the first array). For 0 values the function should return np.nan since it’s not
Correct usage of numpy.vstack with python’s numba
I am currently trying to speed up some python code using numba. According to the documentation of numba, numpy.meshgrid is not supported but numpy.vstack is. So I replaced the meshgrid call by vstack which works fine when not using numba. It does not work, however, when using numba. Here is the code: And here is the error message: It sounds
Python – Group(Cluster/Sort) arrays based on ranking information
I have a dataframe looks like this: I converted the dataframe into 2D arrays like this: The score of each row 1-5 actually means the people give the scores to item A, B, C, D. I would like to identify the people who have the same ranking, for example the people think A > B > C > D. And