Skip to content
Advertisement

Tag: numpy

Convert dataframe to a rec array (and objects to strings)

I have a pandas dataframe with a mix of datatypes (dtypes) that I wish to convert to a numpy structured array (or record array, basically the same thing in this case). For purely numeric dataframes, this is easy to do with the to_records() method. I also need the dtypes of pandas columns to be converted to strings rather than objects

Finding day of the week for a datetime64

Apologies if this is an easy one but I can’t see anything in the numpy documentation. I have a datetime64 and I’d like to find out which day of the week it is. Unlike python datetime, datetime64 doesn’t seem to have a .weekday() function. However it does have a busday_offset() function, which implies it must know behind-the-scenes what day of

Is there a GUI to see contents of .npy file?

I am working with Python 2. I have saved a dict of arrays to a .npy file on my computer. If I open it as a text file, a just see a mess of ASCII characters, as one would expect since I am not just saving arrays. I can see its contents by np.load it in a Python console, but

How does pytorch broadcasting work?

produces a Tensor with size: torch.Size([4,4]). Can someone provide a logic behind this? Answer PyTorch broadcasting is based on numpy broadcasting semantics which can be understood by reading numpy broadcasting rules or PyTorch broadcasting guide. Expounding the concept with an example would be intuitive to understand it better. So, please see the example below: Now for torch.add(t_rand, t_ones), visualize it

What is the use of bincount() method from numpy?

What is its purpose? I tried reading the official site but wasn’t able to understand. Answer bincount returns the count of values in each bin from 0 to the largest value in the array i.e. e.g. Note: absent numbers (e.g. 5 above) return a count of 0 a ValueError is raised if the list contains negative numbers or NaN

loading EMNIST-letters dataset

I have been trying to find a way to load the EMNIST-letters dataset but without much success. I have found interesting stuff in the structure and can’t wrap my head around what is happening. Here is what I mean: I downloaded the .mat format in here I can load the data using it is a dictionnary with the keys as

Installing numpy with pip on windows 10 for python 3.7

I installed python 3.7 on my Windows 10 laptop since it has been officially released as of today (06/28/2018). Then i tried to install numpy package using pip The install proceeds but finally fails with the below error : Any ideas as to how to overcome this install Error? Thanks. Answer Installing NumPy on Windows is a common problem if

How to generate random numbers with predefined probability distribution?

I would like to implement a function in python (using numpy) that takes a mathematical function (for ex. p(x) = e^(-x) like below) as input and generates random numbers, that are distributed according to that mathematical-function’s probability distribution. And I need to plot them, so we can see the distribution. I need actually exactly a random number generator function for

Advertisement