Convert the decimal numbers expressed in a `numpy.ndarray` into a matrix representing elements in fractional form
MRAB
python at mrabarnett.plus.com
Tue May 17 12:20:54 EDT 2022
On 2022-05-17 16:21, Peter J. Holzer wrote:
> On 2022-05-16 20:48:02 -0400, Dennis Lee Bieber wrote:
>> On Mon, 16 May 2022 17:22:17 -0700 (PDT), "hongy... at gmail.com"
>> <hongyi.zhao at gmail.com> declaimed the following:
>> >a=re.sub(r"'","",a)
>>
>> Explain what you believe this operation is doing, show us the input and
>> the output.
>>
>> The best I can make out of that is that it is looking for single quote
>> characters within whatever "a" is, and replacing them with nothing.
>> Something much more understandable, without invoking a regular expression
>> library (especially when neither the search nor the replacement terms are
>> regular expressions) with simple string operations...
>>
>> stripped = "".join(quoted.split("'"))
>
> Whether that's easier to understand it very much in the eye of the
> beholder.
>
As it's just a simple replacement, I would've thought that the 'obvious'
solution would be:
a = a.replace("'", "")
More information about the Python-list
mailing list