pub fn write_matrix<S, P>(path: P, arr: &ArrayBase<S, Ix2>) -> Result<()>
    where S: nd::Data<Elem=f64>, P: AsRef<Path> {
    let header_nospace = format!("{{'descr': '<f8', 'fortran_order': False, 'shape': ({},{})}}",
        arr.shape()[0], arr.shape()[1]);
    let virtual_len =
        // Calculating how many bytes we have in the header, so we can get alignment
        header_nospace.len()
        + 6 // The magic string
        + 2 // The version number
        + 2 // An unsigned 2-byte integer for header length
        + 1 ; // Because there will be a \n added
    let padding_needed = (((virtual_len + 15) / 16) * 16) - virtual_len; // to get to the next 16
    
    // Numpy version 1.0
    let mut writer = File::create(path)?;
    writer.write_all(b"\x93NUMPY\x01\x00")?;
    writer.write_u16::<LittleEndian>((header_nospace.len()
        + padding_needed
        + 1) // newline
        // Magic string, version number and 2 bytes for the header length number not included.
        as u16
        )?;
    write!(writer, "{}{}\n", header_nospace, " ".repeat(padding_needed))?;
    unsafe {
        // O(N) array copy without memory overhead.
        assert!(arr.is_standard_layout(), "To write an array it needs to be in C order (for now).");
        // Treat the incoming data as floating point
        writer.write_all(::std::slice::from_raw_parts(arr.as_ptr() as *const u8, arr.len()*8))?;
    };
    Ok(())
}
/// Write an array as a numpy array, fast but only works for native byte order
Write an array as a numpy array, fast but only works for native byte order
Write an array as a numpy array fast but only works for native byte order
pub fn write_matrix<S, P>(path: P, arr: &ArrayBase<S, Ix2>) -> Result<()>
    where S: nd::Data<Elem=f64>, P: AsRef<Path> {
    let header_nospace = format!("{{'descr': '<f8', 'fortran_order': False, 'shape': ({},{})}}",
        arr.shape()[0], arr.shape()[1]);
    let virtual_len =
        // Calculating how many bytes we have in the header, so we can get alignment
        header_nospace.len()
        + 6 // The magic string
        + 2 // The version number
        + 2 // An unsigned 2-byte integer for header length
        + 1 ; // Because there will be a \n added
    let padding_needed = (((virtual_len + 15) / 16) * 16) - virtual_len; // to get to the next 16
    // Numpy version 1.0
    let mut writer = File::create(path)?;
    writer.write_all(b"\x93NUMPY\x01\x00")?;
    writer.write_u16::<LittleEndian>((header_nospace.len()
        + padding_needed
        + 1) // newline
        // Magic string, version number and 2 bytes for the header length number not included.
        as u16
        )?;
    write!(writer, "{}{}\n", header_nospace, " ".repeat(padding_needed))?;
    unsafe {
        // O(N) array copy without memory overhead.
        assert!(arr.is_standard_layout(), "To write an array it needs to be in C order (for now).");
        // Treat the incoming data as floating point
        writer.write_all(::std::slice::from_raw_parts(arr.as_ptr() as *const u8, arr.len()*8))?;
    };
    Ok(())
}
pub fn write_matrix < S , P > ( path : P , arr : & ArrayBase < S , Ix2 > ) -> Result < ( ) > where S : nd :: Data < Elem = f64 > , P : AsRef < Path > { let header_nospace = format ! ( " " arr shape ( ) [ 0 ] arr shape ( ) [ 1 ] ) ; let virtual_len = // Calculating how many bytes we have in the header, so we can get alignment header_nospace . len ( ) + 6 // The magic string + 2 // The version number + 2 // An unsigned 2-byte integer for header length + 1 ; // Because there will be a \n added let padding_needed = ( ( ( virtual_len + 15 ) / 16 ) * 16 ) - virtual_len ; // to get to the next 16 // Numpy version 1.0 let mut writer = File :: create ( path ) ? ; writer . write_all ( b" \x93 \x01 \x00 " ) ? ; writer . write_u16 :: < LittleEndian > ( ( header_nospace . len ( ) + padding_needed + 1 ) // newline // Magic string, version number and 2 bytes for the header length number not included. as u16 ) ? ; write ! ( writer " \n " header_nospace " " repeat ( padding_needed ) ) ? ; unsafe { // O(N) array copy without memory overhead. assert ! ( arr is_standard_layout ( ) " " ) ; // Treat the incoming data as floating point writer . write_all ( :: std :: slice :: from_raw_parts ( arr . as_ptr ( ) as * const u8 , arr . len ( ) * 8 ) ) ? ; } ; Ok ( ( ) ) }
Write an array as a numpy array, fast but only works for native byte order
Write an array as a numpy array fast but only works for native byte order
path
P
arr
&ArrayBase<S, Ix2>
path
P
arr
&ArrayBase<S, Ix2>