Relative Content

Tag Archive for pythonarraysnumpy

Rolling a two-valued array until its sorted

I have an array consisting of two values a and b. (In my case these are strings). The array, in the physical interpretation, is periodic, so if N is the length of the array arr, then arr[n+N]=arr[n]. How do I roll the array such that it has the form [a, a, ..., a, b, ..., b, b] i.e. sorted or grouped into two parts within the context of the definition of array (physically it will remain the same because I will roll the physical quantity in the same way too, of which this array is a label)?

Comparing column of dataframe to all elements of a numpy array in python

I am new python (and to coding in general) so apologies if this question isn’t the most descriptive.
I am trying to compare a string value of company names in a dataframe to a series of company names in a numpy array. If the company name in the dataframe matches any of the names in the numpy array, I want it to return 1. Otherwise I want it to return zero.