小编al2*_*al2的帖子

How to resize array to a certain length proportionally?

I have an array of n length and I want to resize it to a certain length conserving the proportions.

I would like a function like this:

def rezise_my_array(array, new_lentgh)
Run Code Online (Sandbox Code Playgroud)

For example, the input would be an array of length 9:

l = [1,2,3,4,5,6,7,8,9]
Run Code Online (Sandbox Code Playgroud)

If I rezise it to length 5, the output would be:

[1,3,5,7,9]
Run Code Online (Sandbox Code Playgroud)

or vice versa.

I need this to create a linear regression model on pyspark, since all the features must have the same length.

python numpy

5
推荐指数
1
解决办法
62
查看次数

标签 统计

numpy ×1

python ×1