First about me
University student, research on sound, programming in swift.
Declaration of initialization of two-dimensional array and calculation of array elements in swift
Currently, it is implemented by handling 2D arrays in swift. I thought that it would be more convenient to initialize the array first as I implemented it, so I would like to help you with the two-dimensional array initialization declaration. In addition, since it is necessary to calculate the elements of the array, I would like to seek advice on the calculation of the arrays.
What is the two-dimensional array initialization declaration?
var buffer: [[Float]] = [[Float]] (repeating: [Int] (repeating: 0.0, count: nframe), count: 1)
* Nframe contains a value of 6000.
When initialized like this, I tried to implement it because I saw it on other webs
Type of expression is ambiguous without more context and error display.
The content was ambiguous and angry
let nframe = 6000
var buffer: [[Float]] = Array >()
var buffer2: [Float]! = Array (repeating: 0.0, count: buffer2size)
var y: [Float] = Array (repeating: 0.0, count: nframe)
for i in 0 ..<nChannel {
for n in 0 ..<nframe {
for k in 0 ..<buffer2size {
y [n] + = buffer [i] [n-k] * buffer2 [k]
}
}
}
nChannel is 0 (i.e. 1Channel), nframe is 6000, buffer2size is 600.
There are 6000 values in the buffer. buffer2 contains 600 values.
What I want to do is multiply-add operation.
This is an attempt to multiply the values stored in buffer and buffer2 above and put the sum of the products looped up to 600 times in y [n].
However, the following error occurs:
error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code = EXC_I386_INVOP, subcode = 0x0).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
Thank you.
Supplemental information (FW/tool version etc.)swift5, xcode13.2
-
Answer # 1
-
Answer # 2
Premises for using arrays
Check if the stored array contains data properly (you can see the contents by using print debugging or playground), and writing code that exceeds the array index will result in an index out of range. It is careful about how to use.
Related articles
- call swift from objective-c
- Swift and Objective-C mixing considerations
- Implementation code for sorting multidimensional arrays by specified value in php
- Writing Objective-C classes in Swift and inheriting Objective-C classes
- Swift, Objective-C, Cocoa hybrid programming setup guide
- Swift calls API instance written in Objective-C
- How to transfer Objective-c code to Swift code
- Detailed use of one-dimensional arrays and multi-dimensional arrays in C # programming
- concatenation of multi-dimensional arrays (objects) in javascript
- Can Swift replace Objective-C?
- swift - i want to get the index number of the contents of a multi-dimensional array by specifying the condition and selecting it
- swift - i want to sort the contents of a multidimensional array in descending order
- objective-c - questions about the behavior of swift seachbar
- initializing multidimensional arrays with coffeescript
- in swift, what is the id (generic type) that corresponds to objective-c?
- multidimensional arrays - i want to rotate multiple arrays in a for in statement
- multidimensional arrays - when replacing a part of a two-dimensional array and drawing an image based on it, the newly created a
- PHP uses array_multisort to sort multiple arrays or multidimensional arrays
- Swift calls Objective-C code
- about php multidimensional arrays
- objective-c - storyboard isn't there a table with standard controls?
- objective-c - does mfmailcomposeviewcontrollerdelegate not work in the simulator?
- objective-c - i want to change swift index type to int type
- objective-c - about phpickerviewcontroller for ios14
- objective-c - swift search position for the specified character
- call swift from objective-c
- xcode - i get an error when i try to install and build an external library
- xcode - i want to assign a variable value depending on the screen aspect ratio of swiftui/iphone
- xcode - [swift] contents of collectionviewcell change every time reloaddate is performed
- ios - swift5 video playback
Only for the time being.
Changing [Int] in the middle to [Float] should compile.