How to modify some characters in an array of strings?
I have this variable :
terms2 = ['5*x^4', '4*x^3', '2/x^2']
I neew to make some changes when '/' appears and after that terms2 should be:
terms2 = ['5*x^4', '4*x^3', '2*x^2']
I've been shearching for a way to do this for some days, thanks.
See also questions close to this topic

first element to become the key each row
I have a csv file that contains 2 columns. Here is an glimpse of how he looks:
A:john, robert, simon,peter B: robert, isiah, elephant C: james, bond, jack, chuck
What I want is to be able to make every element of the first row a the key of the dictionary and make the rest of the row the value. basically I want it to look this:
A B C john robert james robert isiah bond peter elephant jack chuck

How to make all fields readonly in form view odoo?
I was trying to make all fields in a form view readonly in odoov10. Is there any python method through I can get all the form view fields and change its attribute to readonly="True"?

Calculate new column as the mean of other columns pandas
I have a this data frame:
and I would like to calculate a new columns as de the mean of
salary_1
,salary_2
andsalary_3
.df = pd.DataFrame({'salary_1':[230,345,222],'salary_2':[235,375,292],'salary_3':[210,385,260]}) salary_1 salary_2 salary_3 0 230 235 210 1 345 375 385 2 222 292 260
How can I do it in pandas in the most efficient way? Actually I have many more columns and I don't want to write this one by one.
Something like this:
salary_1 salary_2 salary_3 salary_mean 0 230 235 210 (230+235+210)/3 1 345 375 385 ... 2 222 292 260 ...
Thank you!

What is difference array ? how to use it?
Could anyone please help me to understand difference array ?

move along a grid in Unity
I can set four different movement directions for my player
 Vector2.up => (0,1)
 Vector2.down => (0,1)
 Vector2.left => (1,0)
 Vector2.right => (1,0)
and I have a two dimensional array that contains
Cell
objectspublic class Cell { public Cell(GameObject cellObject, bool isObstacle) { CellObject = cellObject; IsObstacle = isObstacle; } public GameObject CellObject { get; set; } public bool IsObstacle { get; set; } }
My array is initialized by the size of the map.
private const int MAP_SIZE = 10; private Cell[,] mapCells = new Cell[MAP_SIZE, MAP_SIZE];
I fill this array by using two loops, this will give me 100 cells.
for (int x = 0; x < MAP_SIZE; x++) { for (int y = 0; y < MAP_SIZE; y++) { Vector3 newCellPosition = new Vector3(x, 0, y); GameObject newCellObject = Instantiate(cell, newCellPosition, cell.transform.rotation); bool isObstacle = false; // TEST Cell newCell = new Cell(newCellObject, isObstacle); mapCells[x, y] = newCell; } }
When moving the player I want to return the
Cell
he has to move to. The movementDirection parameter will set the row and the column to search for.If there is an obstacle cell the player should just move to this obstacle and stop.
public Cell GetTargetCell(Vector2 movementDirection) { Cell targetCell = null; // get the path // get the closest obstacle return targetCell; }
Is there an elegant way to calculate the correct target cell by a 2D direction?

SEARCH for row number by column values
Let's suppose I have this array.
import numpy as np M = np.random.rand(10,4)
I want to do the following: if the 1st column in the i'th row has value <=a, and the sum of the 3rd and 4th column of the same row =b, then I want the program to return the value if the 3nd column of the row.
In my case, there will be a unique case where both of the above conditions are satisfied (i.e. 1st column of the row has value <=a, and the sum of the 3rd and 4th column of the same row =b)  so I guess, essentially I am looking for a way to find in which row this holds.
I tried with
if M[:,1] == i and M [:,3] + M[:,4]  1 <= j:
but am stuck on how to continue.
How can I accomplish this?
Cheers!

changing reference to string object, isn't technically changing its value?
I understood how strings are immutable in java, but my question is,isn't changing reference to string object serve the purpose of changing content of string? Take for example:
String s1 = "abc"
now here
s1
refers to"abc"
, Now if I do:s1 = "xyz"
I know that new string object has been created and now
s1
refers to"xyz"
so now if we prints1
it will printxyz
But the question remains the same, didn't we just change the string value(whatever may be underlying logic for that),didn't we loose what we had before in
s1

How to represent editable strings in OCaml
Consider the data type A* of strings over a given alphabet A, which inductively defined as:
1)The empty string (which has no letters) is in A*
2)Each letter a in A is in A*
3)If s_1 and s_2 are strings in A*, then their concatenation s_1 s_2 is in A*
How to define in OCaml an efficient functional data type to represent editable strings (which can be arbitrarily long) over an arbitrary given alphabet.

Python  String distance Matrix: stringdistmatrix (R) equivalent in Python
In R, there is a package, called
stringdist
, which generates a matrix of distance between strings.It provides many distance methods that I need such as :"Optimal string aligment", "Levenshtein", "DamerauLevenshtein distance", "hamming", " Longest common substring distance", "qgram", "cosine", "jaccard", "JaroWinker", "soundex".
The input is just one matrix (1*n) of strings like
1 klksahssahikaskjlasjkhajkshjkahs 2 ahskjahskahsjkahsklsakjskajskaj 3 kahskjahskjahjkshakjshjkahskjsak . . n kahskjahskjahskjhajkhsskjahs
The length of each string could be different.
The output is a n*n matrix which gives the distance between each pair in the above input.
I want to use this distance matrix as in input for
linkage
andfcluster
to cluster them. I triedscipy.spatial.distance.pdist
andsklearn.metrics.pairwise.pairwise_distances
but both do not support strings and gave similar error:could not convert string to float: 'RFLELLKSECHFFNGTERVRFLERHFHNQEEYARFDSDVGEFRAVRELGRPDAEYWNSQKDLLEQKRGQVDNYCRHNYGVGESFTVQRRNA'
Is there any string distance package in Python which provides n*n distance matrix (pairwise distances for strings)?