用空格分隔的数字在Python中创建矩阵

时间:2015-06-19 18:42:15

标签: python matrix

我在.txt中有一个未定义的数字矩阵,只用空格分隔。如何在保持行和列顺序的同时使用python定义矩阵并对其进行操作? .txt文档示例:

moviePlayer = MPMoviePlayerController(contentURL: url)
        moviePlayer.movieSourceType = MPMovieSourceType.File
        moviePlayer.controlStyle = MPMovieControlStyle.None
        moviePlayer.view.backgroundColor = UIColor.blueColor()
        moviePlayer.scalingMode = MPMovieScalingMode.AspectFit
        moviePlayer.repeatMode = MPMovieRepeatMode.None;
        moviePlayer.allowsAirPlay = false
        moviePlayer.shouldAutoplay = false
        moviePlayer.backgroundView.backgroundColor = UIColor.whiteColor()
        moviePlayer.view.frame = self.bounds
        self.addSubview(moviePlayer.view)

1 个答案:

答案 0 :(得分:1)

import numpy as np

mymatrix = np.loadtxt('input_file.txt')

>>> mymatrix

array([[   0.6225,  267.9   ,    0.    ],
       [   0.    ,   -0.    ,    0.    ]])

然后用这个矩阵(2D数组)做任何你喜欢的事情!