Skip to content
Advertisement

Tag: arrays

frequency of unique values for 2d numpy array

I have a 2-dimensional numpy array of following format: now how to print the frequency of unique elements in this 2d numpy array, so that it returns count([1. 0.]) = 1 and count([0. 1.]) = 1? I know how to do this using loops, but is there any better pythonic way to do this. Answer You can use numpy.unique(), for

Variable is not divisible by an unspecific set of Numbers

I just started to code and try to build my first function in Python/NumPy. My first goal was to get a list for all multiplies of 31 which are not divisible by numbers 1>31 and I figured it out Here is the code: The next step is to make the function more flexible, but easy ideas like this just don’t

String handling in Python

I am trying to write a short python function to break a long one_line string into a multi_line string by inserting n. the code works fine when i simply insert n into the string but i get an index out of range error when i insert a conditional check to add hyphenation as well. Here is the code that i

Python: How to extract a List thats inside an array, which is inside a list?

Been trying to figure this out everyday for a week… I am receiving data, then using json.loads and variable-ing it. Here is the print output that I cant seem to further variable-ize without error codes: [548, {‘a’: [‘2364.66000’, 16, ‘16.94656538’], ‘b’: [‘2364.65000’, 8, ‘8.45377850’], ‘c’: [‘2364.66000’, ‘0.35264111’], ‘v’: [‘494.53876892’, ‘54702.28957251’], ‘p’: [‘2363.99238’, ‘2359.02527’], ‘t’: [404, 31739], ‘l’: [‘2355.99000’, ‘2258.59000’], ‘h’:

Supplying varying number of input arguments for np.meshgrid

I have a function that uses np.meshgrid to get the matrix form of supplied co-ordinates. I have a parameter dim that determines what dimension I am working with and needs to return an array with dim dimension along axis 1. I have attached an MWE below. However my expected output is , which is obtained by replacing return np.array(np.meshgrid([a]*dim)).T.reshape(-1, dim)

comparing numpy arrays with tolerance

I’m trying to compare floating numbers that are stored in numpy arrays. I would like them to be compared with a tolerance and every number of the array should be compared with every number of the other array. My attempt is shown underneath, I used two simple arrays as examples but it has the problem that it only compares numbers

Reading arrays from .txt file as numbers instead of strings

I’m using an automatic data acquisition software that exports the data as .txt files. I then imported the file into python (using the pandas package and turning the columns into arrays) but I’m facing a problem. Python can’t “read” the data because the automatic data acquisition software exported it into the following number format, and so Python is treating each

Advertisement