小编Jon*_*Kim的帖子

Pillow Image对象和numpy数组之间的转换会更改维度

我正在使用Pillow和numpy,但在Pillow Image对象和numpy数组之间进行转换时遇到问题.

当我执行以下代码时,结果很奇怪.

im = Image.open(os.path.join(self.img_path, ifname))
print im.size
in_data = np.asarray(im, dtype=np.uint8)
print in_data.shape
Run Code Online (Sandbox Code Playgroud)

结果是

(1024, 768)
(768, 1024)
Run Code Online (Sandbox Code Playgroud)

尺寸为何改变?

python arrays numpy python-imaging-library pillow

23
推荐指数
2
解决办法
2万
查看次数

在Mac OS X上使用pip安装pyopencv

我试图在OS X Mountain Lion中使用pip安装pyopencv,但导致setuptools失败.以下是我的工作.setuptools中的"库"是什么?我之前没见过.我已经通过自制软件和其他东西安装了opencv.在pyopencv的doucmentation中,它没有解释使用pip only source install的安装,

(img2)appleparan@LiamMac src $ brew install cmake
Warning: cmake-2.8.11.2 already installed
(img2)appleparan@LiamMac src $ brew install cmake --upgrade
Warning: cmake-2.8.11.2 already installed
(img2)appleparan@LiamMac src $ brew install opencv
Warning: opencv-2.4.6.1 already installed
(img2)appleparan@LiamMac src $ brew install boost
Warning: boost-1.54.0 already installed
(img2)appleparan@LiamMac src $ pip install pyopencv
Downloading/unpacking pyopencv
  Could not find a version that satisfies the requirement pyopencv (from versions: 2.0.wr1.0.1-demo, 2.0.wr1.0.1, 2.0.wr1.1.0, 2.1.0.wr1.0.0, 2.1.0.wr1.0.1, 2.1.0.wr1.0.2, 2.1.0.wr1.1.0, 2.1.0.wr1.2.0, 2.1.0.wr1.2.0-demo, 2.1.0.wr1.2.0)
Cleaning up... …
Run Code Online (Sandbox Code Playgroud)

python opencv pip setuptools

6
推荐指数
1
解决办法
3697
查看次数

Julia与numpy的where函数等效吗?

在python中,where在numpy中根据给定条件选择数组中的元素。

>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.where(a < 5, a, 10*a)
array([ 0,  1,  2,  3,  4, 50, 60, 70, 80, 90])
Run Code Online (Sandbox Code Playgroud)

那朱莉娅呢?filter将用作选择元素,但如果if不使用表达式,它将删除其他元素。但是,我不想使用if

我是否需要为filter(不使用if)或任何其他替代方法编写更复杂的函数?

编辑:我找到了解决方案,但如果有人对此有更好的主意,请回答此问题。

julia > a = collect(1:10)
10-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

julia> cond = a .< 5
10-element BitArray{1}:
  true
  true
  true
  true
 false …
Run Code Online (Sandbox Code Playgroud)

julia

4
推荐指数
1
解决办法
262
查看次数

在 Julia 中将 3D 数组转换为 2D 数组的数组的最有效方法是什么?

主题说明了一切。

我只想这样做,但对我来说,分配新数组效率很低。

julia> a = reshape(1:30, 2, 3, 5)
Run Code Online (Sandbox Code Playgroud)

进入

julia> b = [a[:, :, i] for i in 1:5]
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法将类型从 转换Array{T, 3}Array{Array{T, 2}, 1}

arrays julia

3
推荐指数
1
解决办法
617
查看次数