Repository: scipy/scipy

Issue:
Scipy mmwrite incorrectly writes the zeros for skew-symmetric, array matrices
When you have a dense, skew-symmetric matrix, and you write it to file using scipy.io.mmwrite and specify that it is a skew-symmetric matrix, the resulting file incorrectly lists the zeros on the diagonal. According to the [matrix market format documentation](http://math.nist.gov/MatrixMarket/formats.html#MMformat), page 9:

> Only entries below the main diagonal
> are stored in the file. The entries on the main diagonal are zero and 
> those above the main diagonal are known by symmetry. 

### Reproducing code example:
```
from scipy.io import mmwrite
matrix = [[0, 1], [-1, 0]]
mmwrite("test.txt", matrix, symmetry="skew-symmetric")
```

### Error message:
The resulting matrix is:
```
%%MatrixMarket matrix array integer skew-symmetric
%
2 2
0
-1
0
```

### Scipy/Numpy/Python version information:
```
0.19.1 1.13.1 sys.version_info(major=3, minor=6, micro=2, releaselevel='final', serial=0)
```



Discussion:
@ilayn Can I (or should I) fix this?
If nobody has mentioned a clear interest you can pick up any issue without asking @tokixix 

 Thank you for effort and interest on the issues so far by the way.

Resolving patch:
diff --git a/scipy/io/mmio.py b/scipy/io/mmio.py
--- a/scipy/io/mmio.py
+++ b/scipy/io/mmio.py
@@ -503,6 +503,10 @@ def _parse_body(self, stream):
             a = zeros((rows, cols), dtype=dtype)
             line = 1
             i, j = 0, 0
+            if is_skew:
+                a[i, j] = 0
+                if i < rows - 1:
+                    i += 1
             while line:
                 line = stream.readline()
                 if not line or line.startswith(b'%'):
@@ -529,8 +533,17 @@ def _parse_body(self, stream):
                         i = 0
                     else:
                         i = j
-            if not (i in [0, j] and j == cols):
-                raise ValueError("Parse error, did not read all lines.")
+                        if is_skew:
+                            a[i, j] = 0
+                            if i < rows-1:
+                                i += 1     
+                                
+            if is_skew:
+                if not (i in [0, j] and j == cols - 1):
+                    raise ValueError("Parse error, did not read all lines.")
+            else:
+                if not (i in [0, j] and j == cols):
+                    raise ValueError("Parse error, did not read all lines.")
 
         elif format == self.FORMAT_COORDINATE and coo_matrix is None:
             # Read sparse matrix to dense when coo_matrix is not available.
@@ -699,19 +712,22 @@ def _write(self, stream, a, comment='', field=None, precision=None,
             stream.write(asbytes('%%%s\n' % (line)))
 
         template = self._field_template(field, precision)
-
         # write dense format
         if rep == self.FORMAT_ARRAY:
-
             # write shape spec
             stream.write(asbytes('%i %i\n' % (rows, cols)))
 
             if field in (self.FIELD_INTEGER, self.FIELD_REAL):
-
                 if symmetry == self.SYMMETRY_GENERAL:
                     for j in range(cols):
                         for i in range(rows):
                             stream.write(asbytes(template % a[i, j]))
+                            
+                elif symmetry == self.SYMMETRY_SKEW_SYMMETRIC:
+                    for j in range(cols):
+                        for i in range(j + 1, rows):
+                            stream.write(asbytes(template % a[i, j]))
+                            
                 else:
                     for j in range(cols):
                         for i in range(j, rows):


Test patch:
diff --git a/scipy/io/tests/test_mmio.py b/scipy/io/tests/test_mmio.py
--- a/scipy/io/tests/test_mmio.py
+++ b/scipy/io/tests/test_mmio.py
@@ -78,11 +78,11 @@ def test_simple_symmetric_integer(self):
                          (2, 2, 4, 'array', 'integer', 'symmetric'))
 
     def test_simple_skew_symmetric_integer(self):
-        self.check_exact([[1, 2], [-2, 4]],
+        self.check_exact([[0, 2], [-2, 0]],
                          (2, 2, 4, 'array', 'integer', 'skew-symmetric'))
 
     def test_simple_skew_symmetric_float(self):
-        self.check(array([[1, 2], [-2.0, 4]], 'f'),
+        self.check(array([[0, 2], [-2.0, 0.0]], 'f'),
                    (2, 2, 4, 'array', 'real', 'skew-symmetric'))
 
     def test_simple_hermitian_complex(self):