-1

I am using the swift accelerate APIs to process some data. However a few of these data points contain NaN values (result of trying to divide a zero value).

My question is can I easily deal with this using any inbuilt swift function? I am looking at replacing all values of NaN with zero values so that I can still further process these large data sets without an error.

4

1 回答 1

2

您可以使用该map方法将所有NaN值转换为 0 并将所有其他值转换为自身:

let arrayWithoutNaNs = yourArray.map { $0.isNaN ? 0 : $0 }

由于您的数组很长,您可能还需要考虑通过添加.lazybefore来懒惰地执行此操作.map

于 2019-12-10T13:07:40.523 回答