Here is a quick and dirty method to do it,
input = {{0.1875, -0.0625, 0.0625, -0.0625, -0.1875,
0.0625, -0.0625, 0.0625, 0, 0, -0.125, 0.0625, 0, 0}, {-0.0625,
0.1875, 0.0625, -0.0625, 0.0625, -0.1875, -0.0625, 0.0625, 0, 0,
0, -0.0625, 0, 0}}
(* {{0.1875, -0.0625, 0.0625, -0.0625, -0.1875, 0.0625, -0.0625,
0.0625, 0, 0, -0.125, 0.0625, 0, 0}, {-0.0625, 0.1875,
0.0625, -0.0625, 0.0625, -0.1875, -0.0625, 0.0625, 0, 0, 0, -0.0625,
0, 0}} *)
First I convert the list to a string, then I use StringReplace
and copy the result to the clipboard to paste wherever I need it,
CopyToClipboard@
StringReplace[
ToString@input, {"{{" -> "np.array([[", "}, {" -> "], [",
"}}" -> "]])"}]
The output has no line breaks,
np.array([[0.1875, -0.0625, 0.0625, -0.0625, -0.1875, 0.0625, -0.0625, 0.0625, 0, 0, -0.125, 0.0625, 0, 0], [-0.0625, 0.1875, 0.0625, -0.0625, 0.0625, -0.1875, -0.0625, 0.0625, 0, 0, 0, -0.0625, 0, 0]])
A more polished, functional form, which can deal with differently shaped arrays, and with large and small numbers, is
toNumpy = CopyToClipboard[
"np.array(" <>
StringReplace[
ToString[
Map[FortranForm, #, {-1}]]
, {"{" -> "[", "}" -> "]"}] <> ")"
] &;
Some test cases,
toNumpy@RandomReal[10^13, {2, 2, 2}]
np.array([[[6.515662614124779e12, 5.006958562518258e12], [9.038456654284738e12, 6.155528971184453e12]], [[8.352734900856066e12, 3.183407977590039e11], [9.3300341220833e12, 4.83956443633259e12]]])
and
toNumpy@RandomReal[10^-13, {5}]
np.array([2.5981516628601564e-14, 8.152269536832112e-14, 5.284716124977113e-16, 5.3549719092414376e-14, 2.877505407608681e-14])