Passing numpy masked array in RStudio and reticulate

reticulate
python

#1

The following code reproduces the issue. In python, the array junk1 is a masked array with one value masked. In R, it is no longer masked. I am running R3.5.1, on RStudio 1.2.1206.

import numpy as np
import numpy.ma as ma
junk = np.array(range(1, 101))
junk = junk.reshape((10, 10))
junk = np.transpose(junk)
junk1 = ma.array(junk, mask = (junk == 50))
print(junk1)

[[1 11 21 31 41 51 61 71 81 91]
[2 12 22 32 42 52 62 72 82 92]
[3 13 23 33 43 53 63 73 83 93]
[4 14 24 34 44 54 64 74 84 94]
[5 15 25 35 45 55 65 75 85 95]
[6 16 26 36 46 56 66 76 86 96]
[7 17 27 37 47 57 67 77 87 97]
[8 18 28 38 48 58 68 78 88 98]
[9 19 29 39 49 59 69 79 89 99]
[10 20 30 40 -- 60 70 80 90 100]]

junk2 <- py$junk1
junk2
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]

[1,] 1 11 21 31 41 51 61 71 81 91
[2,] 2 12 22 32 42 52 62 72 82 92
[3,] 3 13 23 33 43 53 63 73 83 93
[4,] 4 14 24 34 44 54 64 74 84 94
[5,] 5 15 25 35 45 55 65 75 85 95
[6,] 6 16 26 36 46 56 66 76 86 96
[7,] 7 17 27 37 47 57 67 77 87 97
[8,] 8 18 28 38 48 58 68 78 88 98
[9,] 9 19 29 39 49 59 69 79 89 99
[10,] 10 20 30 40 50 60 70 80 90 100

Is there a proper way to use numpy masked arrays in R?

Thanks,

-Roy


#2

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.