我正在尝试将一小段MATLAB代码转换成python,MATLAB代码如下:
M = 0;
for k=1:i
M = [M, M, M;
M, ones(3^(k-1)), M;
M, M, M];
end
它创建了一个模拟sierpinski地毯的二维数组
我的python实现是这样的:
M = 0
for x in range(1,count):
square = np.array([[M, M, M], [M, np.ones([3**(x-1),3**(x-1)]), M], [M, M,
我有一些python代码,它目前与二维数组硬连接在一起,如下所示:
import numpy as np
data = np.random.rand(5, 5)
width = 3
for y in range(0, data.shape[1] - W + 1):
for x in range(0, data.shape[0] - W + 1):
block = data[x:x+W, y:y+W]
# Do something with this block
现在,这对于二维数组是硬编码的,我想将其扩展到3D和4D数组。当然,我可以为其他维度编写更多
📷
I am working on a clustering problem. I have 11 features. My complete data frame has 70-80% zeros. The data had outliers that I capped at 0.5 and 0.95 percentile. However, I tried k-means (python) on data and received a very unusual cluster that looks like a cuboid. I am not sure if this result is